Hi,

 I found some issues will setting the bufferSize:

1) bufferSize isn't exactly the max number of bytes of a response body. For example, bufferSize=5 with a "hello" response failed with a byte overflow error. That's bc undertow requires some extra bytes for response headers and others. This is not necessarily wrong but a response/buffer size is usually the max number of bytes for the HTTP body (jetty, netty, others). It is something minor, but will be nice to change this to represent the max size of the HTTP body.

2) bufferSize is ignored when Content-Length is set. Here are some logs from Apache HTTP client calling Undertow and Jetty with a buffer size of 20 bytes.

Undertow: output size is 40bytes, buffer size is 20 bytes
2015/03/01 21:30:32:053 ART [DEBUG] wire - http-outgoing-0 >> "GET /?data=ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMN&len=40 HTTP/1.1[\r][\n]"
2015/03/01 21:30:32:053 ART [DEBUG] wire - http-outgoing-0 >> "Host: localhost:54697[\r][\n]"
2015/03/01 21:30:32:053 ART [DEBUG] wire - http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
2015/03/01 21:30:32:054 ART [DEBUG] wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.4-beta1 (Java 1.5 minimum; Java/1.8.0)[\r][\n]"
2015/03/01 21:30:32:054 ART [DEBUG] wire - http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
2015/03/01 21:30:32:054 ART [DEBUG] wire - http-outgoing-0 >> "[\r][\n]"
2015/03/01 21:30:32:120 ART [DEBUG] wire - http-outgoing-0 << "HTTP/1.1 200 OK[\r][\n]"
2015/03/01 21:30:32:122 ART [DEBUG] wire - http-outgoing-0 << "Content-Type: text/html;charset=UTF-8[\r][\n]"
2015/03/01 21:30:32:122 ART [DEBUG] wire - http-outgoing-0 << "Content-Length: 40[\r][\n]"
2015/03/01 21:30:32:122 ART [DEBUG] wire - http-outgoing-0 << "Date: Mon, 02 Mar 2015 00:30:32 GMT[\r][\n]"
2015/03/01 21:30:32:122 ART [DEBUG] wire - http-outgoing-0 << "[\r][\n]"
2015/03/01 21:30:32:122 ART [DEBUG] wire - http-outgoing-0 << "ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMN"

Jetty:  output size is 40bytes, buffer size is 20 bytes
2015/03/01 21:33:07:956 ART [DEBUG] wire - http-outgoing-1 >> "GET /?data=ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMN&len=40 HTTP/1.1[\r][\n]"
2015/03/01 21:33:07:957 ART [DEBUG] wire - http-outgoing-1 >> "Host: localhost:54732[\r][\n]"
2015/03/01 21:33:07:957 ART [DEBUG] wire - http-outgoing-1 >> "Connection: Keep-Alive[\r][\n]"
2015/03/01 21:33:07:957 ART [DEBUG] wire - http-outgoing-1 >> "User-Agent: Apache-HttpClient/4.4-beta1 (Java 1.5 minimum; Java/1.8.0)[\r][\n]"
2015/03/01 21:33:07:957 ART [DEBUG] wire - http-outgoing-1 >> "Accept-Encoding: gzip,deflate[\r][\n]"
2015/03/01 21:33:07:957 ART [DEBUG] wire - http-outgoing-1 >> "[\r][\n]"
2015/03/01 21:33:07:959 ART [DEBUG] wire - http-outgoing-1 << "HTTP/1.1 200 OK[\r][\n]"
2015/03/01 21:33:07:959 ART [DEBUG] wire - http-outgoing-1 << "Content-Type: text/html;charset=UTF-8[\r][\n]"
2015/03/01 21:33:07:959 ART [DEBUG] wire - http-outgoing-1 << "Content-Length: 40[\r][\n]"
2015/03/01 21:33:07:959 ART [DEBUG] wire - http-outgoing-1 << "[\r][\n]"
2015/03/01 21:33:07:959 ART [DEBUG] wire - http-outgoing-1 << "ABCDEFGHIJKLMNOPQRST"
2015/03/01 21:33:07:959 ART [DEBUG] headers - http-outgoing-1 << HTTP/1.1 200 OK
2015/03/01 21:33:07:959 ART [DEBUG] headers - http-outgoing-1 << Content-Type: text/html;charset=UTF-8
2015/03/01 21:33:07:959 ART [DEBUG] headers - http-outgoing-1 << Content-Length: 40
2015/03/01 21:33:07:960 ART [DEBUG] MainClientExec - Connection can be kept alive indefinitely
2015/03/01 21:33:07:960 ART [DEBUG] wire - http-outgoing-1 << "UVWXYZABCDEFGHIJKLMN"


As you can see, undertow seems to ignore the bufferSize option and it sends the whole output at once, while jetty sent two chunks of 20 bytes each.

BufferSize work when Transfer-Encoding: Chunked is set, but ignored when Content-Length is set. I didn't try with larger files but this makes me worry bc I think sending a large file and setting Content-Length might result in an OOM error.

Found this in latest beta release: 1.2.0beta8 using exchange.getOutputStream (blocking mode)

Thanks


--
edgar