hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Carl D'Halluin (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (HTTPCLIENT-1376) HttpClient incorrectly reuses HTTP/1.1 connection - the response body of the first request is considered as the response for the second request
Date Wed, 19 Jun 2013 18:53:20 GMT

    [ https://issues.apache.org/jira/browse/HTTPCLIENT-1376?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13688306#comment-13688306 ] 

Carl D'Halluin edited comment on HTTPCLIENT-1376 at 6/19/13 6:53 PM:
---------------------------------------------------------------------

Here is tcp dump with some comments


HttpClient creates a new connection to server (who is running at port 8777)


20:39:12.708147 IP 127.0.0.1.50866 > 127.0.0.1.8777: Flags [S], seq 4262098327, win 65535, options [mss 16344,nop,wscale 1,nop,nop,TS val 218887091 ecr 0,sackOK,eol], length 0
	0x0000:  4500 0040 39b4 4000 4006 0000 7f00 0001  E..@9.@.@.......
	0x0010:  7f00 0001 c6b2 2249 fe0a 7597 0000 0000  ......"I..u.....
	0x0020:  b002 ffff fe34 0000 0204 3fd8 0103 0301  .....4....?.....
	0x0030:  0101 080a 0d0b f3b3 0000 0000 0402 0000  ................

20:39:12.708204 IP 127.0.0.1.8777 > 127.0.0.1.50866: Flags [S.], seq 1639494292, ack 4262098328, win 65535, options [mss 16344,nop,wscale 1,nop,nop,TS val 218887091 ecr 218887091,sackOK,eol], length 0
	0x0000:  4500 0040 729f 4000 4006 0000 7f00 0001  E..@r.@.@.......
	0x0010:  7f00 0001 2249 c6b2 61b8 b294 fe0a 7598  ...."I..a.....u.
	0x0020:  b012 ffff fe34 0000 0204 3fd8 0103 0301  .....4....?.....
	0x0030:  0101 080a 0d0b f3b3 0d0b f3b3 0402 0000  ................

20:39:12.708215 IP 127.0.0.1.50866 > 127.0.0.1.8777: Flags [.], ack 1, win 40830, options [nop,nop,TS val 218887091 ecr 218887091], length 0
	0x0000:  4500 0034 a5c6 4000 4006 0000 7f00 0001  E..4..@.@.......
	0x0010:  7f00 0001 c6b2 2249 fe0a 7598 61b8 b295  ......"I..u.a...
	0x0020:  8010 9f7e fe28 0000 0101 080a 0d0b f3b3  ...~.(..........
	0x0030:  0d0b f3b3                                ....


HttpClient sends a request to a resource requiring authentication


20:39:12.748544 IP 127.0.0.1.50866 > 127.0.0.1.8777: Flags [P.], seq 1:131, ack 1, win 40830, options [nop,nop,TS val 218887131 ecr 218887091], length 130
	0x0000:  4500 00b6 7987 4000 4006 0000 7f00 0001  E...y.@.@.......
	0x0010:  7f00 0001 c6b2 2249 fe0a 7598 61b8 b295  ......"I..u.a...
	0x0020:  8018 9f7e feaa 0000 0101 080a 0d0b f3db  ...~............
	0x0030:  0d0b f3b3 4745 5420 2f61 7574 6865 6e74  ....GET./authent
	0x0040:  6963 6174 6564 2e68 746d 6c20 4854 5450  icated.html.HTTP
	0x0050:  2f31 2e31 0d0a 486f 7374 3a20 3132 372e  /1.1..Host:.127.
	0x0060:  302e 302e 313a 3837 3737 0d0a 436f 6e6e  0.0.1:8777..Conn
	0x0070:  6563 7469 6f6e 3a20 4b65 6570 2d41 6c69  ection:.Keep-Ali
	0x0080:  7665 0d0a 5573 6572 2d41 6765 6e74 3a20  ve..User-Agent:.
	0x0090:  4170 6163 6865 2d48 7474 7043 6c69 656e  Apache-HttpClien
	0x00a0:  742f 342e 322e 3420 286a 6176 6120 312e  t/4.2.4.(java.1.
	0x00b0:  3529 0d0a 0d0a                           5)....

20:39:12.748584 IP 127.0.0.1.8777 > 127.0.0.1.50866: Flags [.], ack 131, win 40765, options [nop,nop,TS val 218887131 ecr 218887131], length 0
	0x0000:  4500 0034 f395 4000 4006 0000 7f00 0001  E..4..@.@.......
	0x0010:  7f00 0001 2249 c6b2 61b8 b295 fe0a 761a  ...."I..a.....v.
	0x0020:  8010 9f3d fe28 0000 0101 080a 0d0b f3db  ...=.(..........
	0x0030:  0d0b f3db                                ....


Server responds with a 401


20:39:12.749493 IP 127.0.0.1.8777 > 127.0.0.1.50866: Flags [P.], seq 1:107, ack 131, win 40830, options [nop,nop,TS val 218887131 ecr 218887131], length 106
	0x0000:  4500 009e f8e4 4000 4006 0000 7f00 0001  E.....@.@.......
	0x0010:  7f00 0001 2249 c6b2 61b8 b295 fe0a 761a  ...."I..a.....v.
	0x0020:  8018 9f7e fe92 0000 0101 080a 0d0b f3db  ...~............
	0x0030:  0d0b f3db 4854 5450 2f31 2e31 2034 3031  ....HTTP/1.1.401
	0x0040:  2055 6e61 7574 686f 7269 7a65 6420 2d20  .Unauthorized.-.
	0x0050:  636c 6965 6e74 2069 7320 2573 0d0a 436f  client.is.%s..Co
	0x0060:  6e74 656e 742d 4c65 6e67 7468 3a20 300d  ntent-Length:.0.
	0x0070:  0a57 5757 2d41 7574 6865 6e74 6963 6174  .WWW-Authenticat
	0x0080:  653a 2042 6173 6963 2072 6561 6c6d 3d22  e:.Basic.realm="
	0x0090:  416d 706c 6964 6174 6122 0d0a 0d0a       Amplidata"....

20:39:12.749508 IP 127.0.0.1.50866 > 127.0.0.1.8777: Flags [.], ack 107, win 40777, options [nop,nop,TS val 218887131 ecr 218887131], length 0
	0x0000:  4500 0034 5197 4000 4006 0000 7f00 0001  E..4Q.@.@.......
	0x0010:  7f00 0001 c6b2 2249 fe0a 761a 61b8 b2ff  ......"I..v.a...
	0x0020:  8010 9f49 fe28 0000 0101 080a 0d0b f3db  ...I.(..........
	0x0030:  0d0b f3db                                ....


HttpClient sends the same request again, now with Authorization header


20:39:12.790950 IP 127.0.0.1.50866 > 127.0.0.1.8777: Flags [P.], seq 131:296, ack 107, win 40830, options [nop,nop,TS val 218887173 ecr 218887131], length 165
	0x0000:  4500 00d9 28e8 4000 4006 0000 7f00 0001  E...(.@.@.......
	0x0010:  7f00 0001 c6b2 2249 fe0a 761a 61b8 b2ff  ......"I..v.a...
	0x0020:  8018 9f7e fecd 0000 0101 080a 0d0b f405  ...~............
	0x0030:  0d0b f3db 4745 5420 2f61 7574 6865 6e74  ....GET./authent
	0x0040:  6963 6174 6564 2e68 746d 6c20 4854 5450  icated.html.HTTP
	0x0050:  2f31 2e31 0d0a 486f 7374 3a20 3132 372e  /1.1..Host:.127.
	0x0060:  302e 302e 313a 3837 3737 0d0a 436f 6e6e  0.0.1:8777..Conn
	0x0070:  6563 7469 6f6e 3a20 4b65 6570 2d41 6c69  ection:.Keep-Ali
	0x0080:  7665 0d0a 5573 6572 2d41 6765 6e74 3a20  ve..User-Agent:.
	0x0090:  4170 6163 6865 2d48 7474 7043 6c69 656e  Apache-HttpClien
	0x00a0:  742f 342e 322e 3420 286a 6176 6120 312e  t/4.2.4.(java.1.
	0x00b0:  3529 0d0a 4175 7468 6f72 697a 6174 696f  5)..Authorizatio
	0x00c0:  6e3a 2042 6173 6963 2064 584e 6c63 6a70  n:.Basic.dXNlcjp
	0x00d0:  7759 584e 7a0d 0a0d 0a                   wYXNz....

20:39:12.790989 IP 127.0.0.1.8777 > 127.0.0.1.50866: Flags [.], ack 296, win 40747, options [nop,nop,TS val 218887173 ecr 218887173], length 0
	0x0000:  4500 0034 bef4 4000 4006 0000 7f00 0001  E..4..@.@.......
	0x0010:  7f00 0001 2249 c6b2 61b8 b2ff fe0a 76bf  ...."I..a.....v.
	0x0020:  8010 9f2b fe28 0000 0101 080a 0d0b f405  ...+.(..........
	0x0030:  0d0b f405                                ....


Server sends the 200 response, but the response is a bit weird:
- no content-length, or transfer-encoding or connection:close header
- the body of the response looks very much like another HTTP response
- The rules on what a client should do are not very clear but I would expect client to read stream till EOF and then close connection
- see http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.4


20:39:12.791130 IP 127.0.0.1.8777 > 127.0.0.1.50866: Flags [P.], seq 107:221, ack 296, win 40830, options [nop,nop,TS val 218887173 ecr 218887173], length 114
	0x0000:  4500 00a6 99d3 4000 4006 0000 7f00 0001  E.....@.@.......
	0x0010:  7f00 0001 2249 c6b2 61b8 b2ff fe0a 76bf  ...."I..a.....v.
	0x0020:  8018 9f7e fe9a 0000 0101 080a 0d0b f405  ...~............
	0x0030:  0d0b f405 4854 5450 2f31 2e31 2032 3030  ....HTTP/1.1.200
	0x0040:  204f 4b20 2d20 636c 6965 6e74 2069 7320  .OK.-.client.is.
	0x0050:  3132 372e 302e 302e 313a 3530 3836 360d  127.0.0.1:50866.
	0x0060:  0a0d 0a48 5454 502f 312e 3120 3430 3020  ...HTTP/1.1.400.
	0x0070:  5468 6973 2069 7320 6120 7265 7175 6573  This.is.a.reques
	0x0080:  7420 626f 6479 202d 2063 6c69 656e 7420  t.body.-.client.
	0x0090:  6973 2031 3237 2e30 2e30 2e31 3a35 3038  is.127.0.0.1:508
	0x00a0:  3636 0d0a 0d0a                           66....

20:39:12.791150 IP 127.0.0.1.50866 > 127.0.0.1.8777: Flags [.], ack 221, win 40773, options [nop,nop,TS val 218887173 ecr 218887173], length 0
	0x0000:  4500 0034 a5ab 4000 4006 0000 7f00 0001  E..4..@.@.......
	0x0010:  7f00 0001 c6b2 2249 fe0a 76bf 61b8 b371  ......"I..v.a..q
	0x0020:  8010 9f45 fe28 0000 0101 080a 0d0b f405  ...E.(..........
	0x0030:  0d0b f405                                ....


Server closes (his side of) the connection. Client kernel acknowledges that server has
proposed to close his part of the TCP socket.


20:39:12.791212 IP 127.0.0.1.8777 > 127.0.0.1.50866: Flags [F.], seq 221, ack 296, win 40830, options [nop,nop,TS val 218887173 ecr 218887173], length 0
	0x0000:  4500 0034 a7a6 4000 4006 0000 7f00 0001  E..4..@.@.......
	0x0010:  7f00 0001 2249 c6b2 61b8 b371 fe0a 76bf  ...."I..a..q..v.
	0x0020:  8011 9f7e fe28 0000 0101 080a 0d0b f405  ...~.(..........
	0x0030:  0d0b f405                                ....

20:39:12.791226 IP 127.0.0.1.50866 > 127.0.0.1.8777: Flags [.], ack 222, win 40773, options [nop,nop,TS val 218887173 ecr 218887173], length 0
	0x0000:  4500 0034 36d3 4000 4006 0000 7f00 0001  E..46.@.@.......
	0x0010:  7f00 0001 c6b2 2249 fe0a 76bf 61b8 b372  ......"I..v.a..r
	0x0020:  8010 9f45 fe28 0000 0101 080a 0d0b f405  ...E.(..........
	0x0030:  0d0b f405                                ....

20:39:12.791257 IP 127.0.0.1.8777 > 127.0.0.1.50866: Flags [.], ack 296, win 40830, options [nop,nop,TS val 218887173 ecr 218887173], length 0
	0x0000:  4500 0034 6ac8 4000 4006 0000 7f00 0001  E..4j.@.@.......
	0x0010:  7f00 0001 2249 c6b2 61b8 b372 fe0a 76bf  ...."I..a..r..v.
	0x0020:  8010 9f7e fe28 0000 0101 080a 0d0b f405  ...~.(..........
	0x0030:  0d0b f405                                ....


Although HTTP protocol should NOT reuse the connection, here we see HttpClient send the next request on the same connection.
The server application code will never receive this request!


20:39:12.795330 IP 127.0.0.1.50866 > 127.0.0.1.8777: Flags [P.], seq 296:426, ack 222, win 40830, options [nop,nop,TS val 218887177 ecr 218887173], length 130
	0x0000:  4500 00b6 b1b5 4000 4006 0000 7f00 0001  E.....@.@.......
	0x0010:  7f00 0001 c6b2 2249 fe0a 76bf 61b8 b372  ......"I..v.a..r
	0x0020:  8018 9f7e feaa 0000 0101 080a 0d0b f409  ...~............
	0x0030:  0d0b f405 4745 5420 2f61 7574 6865 6e74  ....GET./authent
	0x0040:  6963 6174 6564 2e68 746d 6c20 4854 5450  icated.html.HTTP
	0x0050:  2f31 2e31 0d0a 486f 7374 3a20 3132 372e  /1.1..Host:.127.
	0x0060:  302e 302e 313a 3837 3737 0d0a 436f 6e6e  0.0.1:8777..Conn
	0x0070:  6563 7469 6f6e 3a20 4b65 6570 2d41 6c69  ection:.Keep-Ali
	0x0080:  7665 0d0a 5573 6572 2d41 6765 6e74 3a20  ve..User-Agent:.
	0x0090:  4170 6163 6865 2d48 7474 7043 6c69 656e  Apache-HttpClien
	0x00a0:  742f 342e 322e 3420 286a 6176 6120 312e  t/4.2.4.(java.1.
	0x00b0:  3529 0d0a 0d0a                           5)....


The Server had already told the client that server has closed the connection. Yet the client still sends a new request.
The server responds with the TCP Reset bit. The server kernel has never delivered this last request to the server application!


20:39:12.795372 IP 127.0.0.1.8777 > 127.0.0.1.50866: Flags [R], seq 1639494514, win 0, length 0
	0x0000:  4500 0028 94ed 4000 4006 0000 7f00 0001  E..(..@.@.......
	0x0010:  7f00 0001 2249 c6b2 61b8 b372 0000 0000  ...."I..a..r....
	0x0020:  5004 0000 fe1c 0000                      P.......








--------------------------------

The same flow without authentication shows a well-behaving HttpClient which does not reuse the connection

20:49:40.647744 IP 127.0.0.1.50944 > 127.0.0.1.8777: Flags [S], seq 1968143964, win 65535, options [mss 16344,nop,wscale 3,nop,nop,TS val 219512758 ecr 0,sackOK,eol], length 0
	0x0000:  4500 0040 bd64 4000 4006 0000 7f00 0001  E..@.d@.@.......
	0x0010:  7f00 0001 c700 2249 754f 7e5c 0000 0000  ......"IuO~\....
	0x0020:  b002 ffff fe34 0000 0204 3fd8 0103 0303  .....4....?.....
	0x0030:  0101 080a 0d15 7fb6 0000 0000 0402 0000  ................

20:49:40.647813 IP 127.0.0.1.8777 > 127.0.0.1.50944: Flags [S.], seq 967349206, ack 1968143965, win 65535, options [mss 16344,nop,wscale 3,nop,nop,TS val 219512758 ecr 219512758,sackOK,eol], length 0
	0x0000:  4500 0040 bc4b 4000 4006 0000 7f00 0001  E..@.K@.@.......
	0x0010:  7f00 0001 2249 c700 39a8 93d6 754f 7e5d  ...."I..9...uO~]
	0x0020:  b012 ffff fe34 0000 0204 3fd8 0103 0303  .....4....?.....
	0x0030:  0101 080a 0d15 7fb6 0d15 7fb6 0402 0000  ................

20:49:40.647823 IP 127.0.0.1.50944 > 127.0.0.1.8777: Flags [.], ack 1, win 65535, options [nop,nop,TS val 219512758 ecr 219512758], length 0
	0x0000:  4500 0034 516f 4000 4006 0000 7f00 0001  E..4Qo@.@.......
	0x0010:  7f00 0001 c700 2249 754f 7e5d 39a8 93d7  ......"IuO~]9...
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fb6  .....(..........
	0x0030:  0d15 7fb6                                ....

20:49:40.647833 IP 127.0.0.1.8777 > 127.0.0.1.50944: Flags [.], ack 1, win 65535, options [nop,nop,TS val 219512758 ecr 219512758], length 0
	0x0000:  4500 0034 7a46 4000 4006 0000 7f00 0001  E..4zF@.@.......
	0x0010:  7f00 0001 2249 c700 39a8 93d7 754f 7e5d  ...."I..9...uO~]
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fb6  .....(..........
	0x0030:  0d15 7fb6                                ....

20:49:40.684643 IP 127.0.0.1.50944 > 127.0.0.1.8777: Flags [P.], seq 1:135, ack 1, win 65535, options [nop,nop,TS val 219512794 ecr 219512758], length 134
	0x0000:  4500 00ba 0e05 4000 4006 0000 7f00 0001  E.....@.@.......
	0x0010:  7f00 0001 c700 2249 754f 7e5d 39a8 93d7  ......"IuO~]9...
	0x0020:  8018 ffff feae 0000 0101 080a 0d15 7fda  ................
	0x0030:  0d15 7fb6 4745 5420 2f6e 6f6e 2d61 7574  ....GET./non-aut
	0x0040:  6865 6e74 6963 6174 6564 2e68 746d 6c20  henticated.html.
	0x0050:  4854 5450 2f31 2e31 0d0a 486f 7374 3a20  HTTP/1.1..Host:.
	0x0060:  3132 372e 302e 302e 313a 3837 3737 0d0a  127.0.0.1:8777..
	0x0070:  436f 6e6e 6563 7469 6f6e 3a20 4b65 6570  Connection:.Keep
	0x0080:  2d41 6c69 7665 0d0a 5573 6572 2d41 6765  -Alive..User-Age
	0x0090:  6e74 3a20 4170 6163 6865 2d48 7474 7043  nt:.Apache-HttpC
	0x00a0:  6c69 656e 742f 342e 322e 3420 286a 6176  lient/4.2.4.(jav
	0x00b0:  6120 312e 3529 0d0a 0d0a                 a.1.5)....

20:49:40.684706 IP 127.0.0.1.8777 > 127.0.0.1.50944: Flags [.], ack 135, win 65535, options [nop,nop,TS val 219512794 ecr 219512794], length 0
	0x0000:  4500 0034 ed1d 4000 4006 0000 7f00 0001  E..4..@.@.......
	0x0010:  7f00 0001 2249 c700 39a8 93d7 754f 7ee3  ...."I..9...uO~.
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fda  .....(..........
	0x0030:  0d15 7fda                                ....

20:49:40.684898 IP 127.0.0.1.8777 > 127.0.0.1.50944: Flags [P.], seq 1:115, ack 135, win 65535, options [nop,nop,TS val 219512794 ecr 219512794], length 114
	0x0000:  4500 00a6 e32a 4000 4006 0000 7f00 0001  E....*@.@.......
	0x0010:  7f00 0001 2249 c700 39a8 93d7 754f 7ee3  ...."I..9...uO~.
	0x0020:  8018 ffff fe9a 0000 0101 080a 0d15 7fda  ................
	0x0030:  0d15 7fda 4854 5450 2f31 2e31 2032 3030  ....HTTP/1.1.200
	0x0040:  204f 4b20 2d20 636c 6965 6e74 2069 7320  .OK.-.client.is.
	0x0050:  3132 372e 302e 302e 313a 3530 3934 340d  127.0.0.1:50944.
	0x0060:  0a0d 0a48 5454 502f 312e 3120 3430 3020  ...HTTP/1.1.400.
	0x0070:  5468 6973 2069 7320 6120 7265 7175 6573  This.is.a.reques
	0x0080:  7420 626f 6479 202d 2063 6c69 656e 7420  t.body.-.client.
	0x0090:  6973 2031 3237 2e30 2e30 2e31 3a35 3039  is.127.0.0.1:509
	0x00a0:  3434 0d0a 0d0a                           44....

20:49:40.684912 IP 127.0.0.1.50944 > 127.0.0.1.8777: Flags [.], ack 115, win 65535, options [nop,nop,TS val 219512794 ecr 219512794], length 0
	0x0000:  4500 0034 9028 4000 4006 0000 7f00 0001  E..4.(@.@.......
	0x0010:  7f00 0001 c700 2249 754f 7ee3 39a8 9449  ......"IuO~.9..I
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fda  .....(..........
	0x0030:  0d15 7fda                                ....

20:49:40.684945 IP 127.0.0.1.8777 > 127.0.0.1.50944: Flags [F.], seq 115, ack 135, win 65535, options [nop,nop,TS val 219512794 ecr 219512794], length 0
	0x0000:  4500 0034 9760 4000 4006 0000 7f00 0001  E..4.`@.@.......
	0x0010:  7f00 0001 2249 c700 39a8 9449 754f 7ee3  ...."I..9..IuO~.
	0x0020:  8011 ffff fe28 0000 0101 080a 0d15 7fda  .....(..........
	0x0030:  0d15 7fda                                ....

20:49:40.684961 IP 127.0.0.1.50944 > 127.0.0.1.8777: Flags [.], ack 116, win 65535, options [nop,nop,TS val 219512794 ecr 219512794], length 0
	0x0000:  4500 0034 735f 4000 4006 0000 7f00 0001  E..4s_@.@.......
	0x0010:  7f00 0001 c700 2249 754f 7ee3 39a8 944a  ......"IuO~.9..J
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fda  .....(..........
	0x0030:  0d15 7fda                                ....

20:49:40.684968 IP 127.0.0.1.8777 > 127.0.0.1.50944: Flags [.], ack 135, win 65535, options [nop,nop,TS val 219512794 ecr 219512794], length 0
	0x0000:  4500 0034 5744 4000 4006 0000 7f00 0001  E..4WD@.@.......
	0x0010:  7f00 0001 2249 c700 39a8 944a 754f 7ee3  ...."I..9..JuO~.
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fda  .....(..........
	0x0030:  0d15 7fda                                ....

20:49:40.692920 IP 127.0.0.1.50944 > 127.0.0.1.8777: Flags [F.], seq 135, ack 116, win 65535, options [nop,nop,TS val 219512802 ecr 219512794], length 0
	0x0000:  4500 0034 da45 4000 4006 0000 7f00 0001  E..4.E@.@.......
	0x0010:  7f00 0001 c700 2249 754f 7ee3 39a8 944a  ......"IuO~.9..J
	0x0020:  8011 ffff fe28 0000 0101 080a 0d15 7fe2  .....(..........
	0x0030:  0d15 7fda                                ....

20:49:40.692969 IP 127.0.0.1.8777 > 127.0.0.1.50944: Flags [.], ack 136, win 65535, options [nop,nop,TS val 219512802 ecr 219512802], length 0
	0x0000:  4500 0034 9f40 4000 4006 0000 7f00 0001  E..4.@@.@.......
	0x0010:  7f00 0001 2249 c700 39a8 944a 754f 7ee4  ...."I..9..JuO~.
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fe2  .....(..........
	0x0030:  0d15 7fe2                                ....

20:49:40.693664 IP 127.0.0.1.50945 > 127.0.0.1.8777: Flags [S], seq 3021102219, win 65535, options [mss 16344,nop,wscale 3,nop,nop,TS val 219512802 ecr 0,sackOK,eol], length 0
	0x0000:  4500 0040 fc70 4000 4006 0000 7f00 0001  E..@.p@.@.......
	0x0010:  7f00 0001 c701 2249 b412 5c8b 0000 0000  ......"I..\.....
	0x0020:  b002 ffff fe34 0000 0204 3fd8 0103 0303  .....4....?.....
	0x0030:  0101 080a 0d15 7fe2 0000 0000 0402 0000  ................

20:49:40.693717 IP 127.0.0.1.8777 > 127.0.0.1.50945: Flags [S.], seq 1401392165, ack 3021102220, win 65535, options [mss 16344,nop,wscale 3,nop,nop,TS val 219512802 ecr 219512802,sackOK,eol], length 0
	0x0000:  4500 0040 c445 4000 4006 0000 7f00 0001  E..@.E@.@.......
	0x0010:  7f00 0001 2249 c701 5387 8c25 b412 5c8c  ...."I..S..%..\.
	0x0020:  b012 ffff fe34 0000 0204 3fd8 0103 0303  .....4....?.....
	0x0030:  0101 080a 0d15 7fe2 0d15 7fe2 0402 0000  ................

20:49:40.693727 IP 127.0.0.1.50945 > 127.0.0.1.8777: Flags [.], ack 1, win 65535, options [nop,nop,TS val 219512802 ecr 219512802], length 0
	0x0000:  4500 0034 584e 4000 4006 0000 7f00 0001  E..4XN@.@.......
	0x0010:  7f00 0001 c701 2249 b412 5c8c 5387 8c26  ......"I..\.S..&
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fe2  .....(..........
	0x0030:  0d15 7fe2                                ....

20:49:40.693737 IP 127.0.0.1.8777 > 127.0.0.1.50945: Flags [.], ack 1, win 65535, options [nop,nop,TS val 219512802 ecr 219512802], length 0
	0x0000:  4500 0034 221a 4000 4006 0000 7f00 0001  E..4".@.@.......
	0x0010:  7f00 0001 2249 c701 5387 8c26 b412 5c8c  ...."I..S..&..\.
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fe2  .....(..........
	0x0030:  0d15 7fe2                                ....

20:49:40.694338 IP 127.0.0.1.50945 > 127.0.0.1.8777: Flags [P.], seq 1:135, ack 1, win 65535, options [nop,nop,TS val 219512803 ecr 219512802], length 134
	0x0000:  4500 00ba 7b37 4000 4006 0000 7f00 0001  E...{7@.@.......
	0x0010:  7f00 0001 c701 2249 b412 5c8c 5387 8c26  ......"I..\.S..&
	0x0020:  8018 ffff feae 0000 0101 080a 0d15 7fe3  ................
	0x0030:  0d15 7fe2 4745 5420 2f6e 6f6e 2d61 7574  ....GET./non-aut
	0x0040:  6865 6e74 6963 6174 6564 2e68 746d 6c20  henticated.html.
	0x0050:  4854 5450 2f31 2e31 0d0a 486f 7374 3a20  HTTP/1.1..Host:.
	0x0060:  3132 372e 302e 302e 313a 3837 3737 0d0a  127.0.0.1:8777..
	0x0070:  436f 6e6e 6563 7469 6f6e 3a20 4b65 6570  Connection:.Keep
	0x0080:  2d41 6c69 7665 0d0a 5573 6572 2d41 6765  -Alive..User-Age
	0x0090:  6e74 3a20 4170 6163 6865 2d48 7474 7043  nt:.Apache-HttpC
	0x00a0:  6c69 656e 742f 342e 322e 3420 286a 6176  lient/4.2.4.(jav
	0x00b0:  6120 312e 3529 0d0a 0d0a                 a.1.5)....

20:49:40.694358 IP 127.0.0.1.8777 > 127.0.0.1.50945: Flags [.], ack 135, win 65535, options [nop,nop,TS val 219512803 ecr 219512803], length 0
	0x0000:  4500 0034 e455 4000 4006 0000 7f00 0001  E..4.U@.@.......
	0x0010:  7f00 0001 2249 c701 5387 8c26 b412 5d12  ...."I..S..&..].
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fe3  .....(..........
	0x0030:  0d15 7fe3                                ....

20:49:40.694758 IP 127.0.0.1.8777 > 127.0.0.1.50945: Flags [P.], seq 1:115, ack 135, win 65535, options [nop,nop,TS val 219512803 ecr 219512803], length 114
	0x0000:  4500 00a6 2d55 4000 4006 0000 7f00 0001  E...-U@.@.......
	0x0010:  7f00 0001 2249 c701 5387 8c26 b412 5d12  ...."I..S..&..].
	0x0020:  8018 ffff fe9a 0000 0101 080a 0d15 7fe3  ................
	0x0030:  0d15 7fe3 4854 5450 2f31 2e31 2032 3030  ....HTTP/1.1.200
	0x0040:  204f 4b20 2d20 636c 6965 6e74 2069 7320  .OK.-.client.is.
	0x0050:  3132 372e 302e 302e 313a 3530 3934 350d  127.0.0.1:50945.
	0x0060:  0a0d 0a48 5454 502f 312e 3120 3430 3020  ...HTTP/1.1.400.
	0x0070:  5468 6973 2069 7320 6120 7265 7175 6573  This.is.a.reques
	0x0080:  7420 626f 6479 202d 2063 6c69 656e 7420  t.body.-.client.
	0x0090:  6973 2031 3237 2e30 2e30 2e31 3a35 3039  is.127.0.0.1:509
	0x00a0:  3435 0d0a 0d0a                           45....

20:49:40.694776 IP 127.0.0.1.50945 > 127.0.0.1.8777: Flags [.], ack 115, win 65535, options [nop,nop,TS val 219512803 ecr 219512803], length 0
	0x0000:  4500 0034 9b29 4000 4006 0000 7f00 0001  E..4.)@.@.......
	0x0010:  7f00 0001 c701 2249 b412 5d12 5387 8c98  ......"I..].S...
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fe3  .....(..........
	0x0030:  0d15 7fe3                                ....

20:49:40.694789 IP 127.0.0.1.8777 > 127.0.0.1.50945: Flags [F.], seq 115, ack 135, win 65535, options [nop,nop,TS val 219512803 ecr 219512803], length 0
	0x0000:  4500 0034 cd0e 4000 4006 0000 7f00 0001  E..4..@.@.......
	0x0010:  7f00 0001 2249 c701 5387 8c98 b412 5d12  ...."I..S.....].
	0x0020:  8011 ffff fe28 0000 0101 080a 0d15 7fe3  .....(..........
	0x0030:  0d15 7fe3                                ....

20:49:40.694803 IP 127.0.0.1.8777 > 127.0.0.1.50945: Flags [F.], seq 115, ack 135, win 65535, options [nop,nop,TS val 219512803 ecr 219512803], length 0
	0x0000:  4500 0034 4174 4000 4006 0000 7f00 0001  E..4At@.@.......
	0x0010:  7f00 0001 2249 c701 5387 8c98 b412 5d12  ...."I..S.....].
	0x0020:  8011 ffff fe28 0000 0101 080a 0d15 7fe3  .....(..........
	0x0030:  0d15 7fe3                                ....

20:49:40.694811 IP 127.0.0.1.50945 > 127.0.0.1.8777: Flags [.], ack 116, win 65535, options [nop,nop,TS val 219512803 ecr 219512803], length 0
	0x0000:  4500 0034 cd38 4000 4006 0000 7f00 0001  E..4.8@.@.......
	0x0010:  7f00 0001 c701 2249 b412 5d12 5387 8c99  ......"I..].S...
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fe3  .....(..........
	0x0030:  0d15 7fe3                                ....

20:49:40.694816 IP 127.0.0.1.50945 > 127.0.0.1.8777: Flags [.], ack 116, win 65535, options [nop,nop,TS val 219512803 ecr 219512803], length 0
	0x0000:  4500 0034 6b7a 4000 4006 0000 7f00 0001  E..4kz@.@.......
	0x0010:  7f00 0001 c701 2249 b412 5d12 5387 8c99  ......"I..].S...
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fe3  .....(..........
	0x0030:  0d15 7fe3                                ....

20:49:40.694823 IP 127.0.0.1.8777 > 127.0.0.1.50945: Flags [.], ack 135, win 65535, options [nop,nop,TS val 219512803 ecr 219512803], length 0
	0x0000:  4500 0034 e028 4000 4006 0000 7f00 0001  E..4.(@.@.......
	0x0010:  7f00 0001 2249 c701 5387 8c99 b412 5d12  ...."I..S.....].
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fe3  .....(..........
	0x0030:  0d15 7fe3                                ....

20:49:40.695039 IP 127.0.0.1.50945 > 127.0.0.1.8777: Flags [F.], seq 135, ack 116, win 65535, options [nop,nop,TS val 219512803 ecr 219512803], length 0
	0x0000:  4500 0034 980c 4000 4006 0000 7f00 0001  E..4..@.@.......
	0x0010:  7f00 0001 c701 2249 b412 5d12 5387 8c99  ......"I..].S...
	0x0020:  8011 ffff fe28 0000 0101 080a 0d15 7fe3  .....(..........
	0x0030:  0d15 7fe3                                ....

20:49:40.695056 IP 127.0.0.1.8777 > 127.0.0.1.50945: Flags [.], ack 136, win 65535, options [nop,nop,TS val 219512803 ecr 219512803], length 0
	0x0000:  4500 0034 dd73 4000 4006 0000 7f00 0001  E..4.s@.@.......
	0x0010:  7f00 0001 2249 c701 5387 8c99 b412 5d13  ...."I..S.....].
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fe3  .....(..........
	0x0030:  0d15 7fe3                                ....



                
      was (Author: carldhalluin):
    Here is tcp dump with some comments


HttpClient creates a new connection to server (who is running at port 8777)


20:39:12.708147 IP 127.0.0.1.50866 > 127.0.0.1.8777: Flags [S], seq 4262098327, win 65535, options [mss 16344,nop,wscale 1,nop,nop,TS val 218887091 ecr 0,sackOK,eol], length 0
	0x0000:  4500 0040 39b4 4000 4006 0000 7f00 0001  E..@9.@.@.......
	0x0010:  7f00 0001 c6b2 2249 fe0a 7597 0000 0000  ......"I..u.....
	0x0020:  b002 ffff fe34 0000 0204 3fd8 0103 0301  .....4....?.....
	0x0030:  0101 080a 0d0b f3b3 0000 0000 0402 0000  ................
20:39:12.708204 IP 127.0.0.1.8777 > 127.0.0.1.50866: Flags [S.], seq 1639494292, ack 4262098328, win 65535, options [mss 16344,nop,wscale 1,nop,nop,TS val 218887091 ecr 218887091,sackOK,eol], length 0
	0x0000:  4500 0040 729f 4000 4006 0000 7f00 0001  E..@r.@.@.......
	0x0010:  7f00 0001 2249 c6b2 61b8 b294 fe0a 7598  ...."I..a.....u.
	0x0020:  b012 ffff fe34 0000 0204 3fd8 0103 0301  .....4....?.....
	0x0030:  0101 080a 0d0b f3b3 0d0b f3b3 0402 0000  ................
20:39:12.708215 IP 127.0.0.1.50866 > 127.0.0.1.8777: Flags [.], ack 1, win 40830, options [nop,nop,TS val 218887091 ecr 218887091], length 0
	0x0000:  4500 0034 a5c6 4000 4006 0000 7f00 0001  E..4..@.@.......
	0x0010:  7f00 0001 c6b2 2249 fe0a 7598 61b8 b295  ......"I..u.a...
	0x0020:  8010 9f7e fe28 0000 0101 080a 0d0b f3b3  ...~.(..........
	0x0030:  0d0b f3b3                                ....


HttpClient sends a request to a resource requiring authentication


20:39:12.748544 IP 127.0.0.1.50866 > 127.0.0.1.8777: Flags [P.], seq 1:131, ack 1, win 40830, options [nop,nop,TS val 218887131 ecr 218887091], length 130
	0x0000:  4500 00b6 7987 4000 4006 0000 7f00 0001  E...y.@.@.......
	0x0010:  7f00 0001 c6b2 2249 fe0a 7598 61b8 b295  ......"I..u.a...
	0x0020:  8018 9f7e feaa 0000 0101 080a 0d0b f3db  ...~............
	0x0030:  0d0b f3b3 4745 5420 2f61 7574 6865 6e74  ....GET./authent
	0x0040:  6963 6174 6564 2e68 746d 6c20 4854 5450  icated.html.HTTP
	0x0050:  2f31 2e31 0d0a 486f 7374 3a20 3132 372e  /1.1..Host:.127.
	0x0060:  302e 302e 313a 3837 3737 0d0a 436f 6e6e  0.0.1:8777..Conn
	0x0070:  6563 7469 6f6e 3a20 4b65 6570 2d41 6c69  ection:.Keep-Ali
	0x0080:  7665 0d0a 5573 6572 2d41 6765 6e74 3a20  ve..User-Agent:.
	0x0090:  4170 6163 6865 2d48 7474 7043 6c69 656e  Apache-HttpClien
	0x00a0:  742f 342e 322e 3420 286a 6176 6120 312e  t/4.2.4.(java.1.
	0x00b0:  3529 0d0a 0d0a                           5)....
20:39:12.748584 IP 127.0.0.1.8777 > 127.0.0.1.50866: Flags [.], ack 131, win 40765, options [nop,nop,TS val 218887131 ecr 218887131], length 0
	0x0000:  4500 0034 f395 4000 4006 0000 7f00 0001  E..4..@.@.......
	0x0010:  7f00 0001 2249 c6b2 61b8 b295 fe0a 761a  ...."I..a.....v.
	0x0020:  8010 9f3d fe28 0000 0101 080a 0d0b f3db  ...=.(..........
	0x0030:  0d0b f3db                                ....


Server responds with a 401


20:39:12.749493 IP 127.0.0.1.8777 > 127.0.0.1.50866: Flags [P.], seq 1:107, ack 131, win 40830, options [nop,nop,TS val 218887131 ecr 218887131], length 106
	0x0000:  4500 009e f8e4 4000 4006 0000 7f00 0001  E.....@.@.......
	0x0010:  7f00 0001 2249 c6b2 61b8 b295 fe0a 761a  ...."I..a.....v.
	0x0020:  8018 9f7e fe92 0000 0101 080a 0d0b f3db  ...~............
	0x0030:  0d0b f3db 4854 5450 2f31 2e31 2034 3031  ....HTTP/1.1.401
	0x0040:  2055 6e61 7574 686f 7269 7a65 6420 2d20  .Unauthorized.-.
	0x0050:  636c 6965 6e74 2069 7320 2573 0d0a 436f  client.is.%s..Co
	0x0060:  6e74 656e 742d 4c65 6e67 7468 3a20 300d  ntent-Length:.0.
	0x0070:  0a57 5757 2d41 7574 6865 6e74 6963 6174  .WWW-Authenticat
	0x0080:  653a 2042 6173 6963 2072 6561 6c6d 3d22  e:.Basic.realm="
	0x0090:  416d 706c 6964 6174 6122 0d0a 0d0a       Amplidata"....
20:39:12.749508 IP 127.0.0.1.50866 > 127.0.0.1.8777: Flags [.], ack 107, win 40777, options [nop,nop,TS val 218887131 ecr 218887131], length 0
	0x0000:  4500 0034 5197 4000 4006 0000 7f00 0001  E..4Q.@.@.......
	0x0010:  7f00 0001 c6b2 2249 fe0a 761a 61b8 b2ff  ......"I..v.a...
	0x0020:  8010 9f49 fe28 0000 0101 080a 0d0b f3db  ...I.(..........
	0x0030:  0d0b f3db                                ....


HttpClient sends the same request again, now with Authorization header


20:39:12.790950 IP 127.0.0.1.50866 > 127.0.0.1.8777: Flags [P.], seq 131:296, ack 107, win 40830, options [nop,nop,TS val 218887173 ecr 218887131], length 165
	0x0000:  4500 00d9 28e8 4000 4006 0000 7f00 0001  E...(.@.@.......
	0x0010:  7f00 0001 c6b2 2249 fe0a 761a 61b8 b2ff  ......"I..v.a...
	0x0020:  8018 9f7e fecd 0000 0101 080a 0d0b f405  ...~............
	0x0030:  0d0b f3db 4745 5420 2f61 7574 6865 6e74  ....GET./authent
	0x0040:  6963 6174 6564 2e68 746d 6c20 4854 5450  icated.html.HTTP
	0x0050:  2f31 2e31 0d0a 486f 7374 3a20 3132 372e  /1.1..Host:.127.
	0x0060:  302e 302e 313a 3837 3737 0d0a 436f 6e6e  0.0.1:8777..Conn
	0x0070:  6563 7469 6f6e 3a20 4b65 6570 2d41 6c69  ection:.Keep-Ali
	0x0080:  7665 0d0a 5573 6572 2d41 6765 6e74 3a20  ve..User-Agent:.
	0x0090:  4170 6163 6865 2d48 7474 7043 6c69 656e  Apache-HttpClien
	0x00a0:  742f 342e 322e 3420 286a 6176 6120 312e  t/4.2.4.(java.1.
	0x00b0:  3529 0d0a 4175 7468 6f72 697a 6174 696f  5)..Authorizatio
	0x00c0:  6e3a 2042 6173 6963 2064 584e 6c63 6a70  n:.Basic.dXNlcjp
	0x00d0:  7759 584e 7a0d 0a0d 0a                   wYXNz....
20:39:12.790989 IP 127.0.0.1.8777 > 127.0.0.1.50866: Flags [.], ack 296, win 40747, options [nop,nop,TS val 218887173 ecr 218887173], length 0
	0x0000:  4500 0034 bef4 4000 4006 0000 7f00 0001  E..4..@.@.......
	0x0010:  7f00 0001 2249 c6b2 61b8 b2ff fe0a 76bf  ...."I..a.....v.
	0x0020:  8010 9f2b fe28 0000 0101 080a 0d0b f405  ...+.(..........
	0x0030:  0d0b f405                                ....


Server sends the 200 response, but the response is a bit weird:
- no content-length, or transfer-encoding or connection:close header
- the body of the response looks very much like another HTTP response
- The rules on what a client should do are not very clear but I would expect client to read stream till EOF and then close connection
- see http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.4


20:39:12.791130 IP 127.0.0.1.8777 > 127.0.0.1.50866: Flags [P.], seq 107:221, ack 296, win 40830, options [nop,nop,TS val 218887173 ecr 218887173], length 114
	0x0000:  4500 00a6 99d3 4000 4006 0000 7f00 0001  E.....@.@.......
	0x0010:  7f00 0001 2249 c6b2 61b8 b2ff fe0a 76bf  ...."I..a.....v.
	0x0020:  8018 9f7e fe9a 0000 0101 080a 0d0b f405  ...~............
	0x0030:  0d0b f405 4854 5450 2f31 2e31 2032 3030  ....HTTP/1.1.200
	0x0040:  204f 4b20 2d20 636c 6965 6e74 2069 7320  .OK.-.client.is.
	0x0050:  3132 372e 302e 302e 313a 3530 3836 360d  127.0.0.1:50866.
	0x0060:  0a0d 0a48 5454 502f 312e 3120 3430 3020  ...HTTP/1.1.400.
	0x0070:  5468 6973 2069 7320 6120 7265 7175 6573  This.is.a.reques
	0x0080:  7420 626f 6479 202d 2063 6c69 656e 7420  t.body.-.client.
	0x0090:  6973 2031 3237 2e30 2e30 2e31 3a35 3038  is.127.0.0.1:508
	0x00a0:  3636 0d0a 0d0a                           66....
20:39:12.791150 IP 127.0.0.1.50866 > 127.0.0.1.8777: Flags [.], ack 221, win 40773, options [nop,nop,TS val 218887173 ecr 218887173], length 0
	0x0000:  4500 0034 a5ab 4000 4006 0000 7f00 0001  E..4..@.@.......
	0x0010:  7f00 0001 c6b2 2249 fe0a 76bf 61b8 b371  ......"I..v.a..q
	0x0020:  8010 9f45 fe28 0000 0101 080a 0d0b f405  ...E.(..........
	0x0030:  0d0b f405                                ....


Server closes (his side of) the connection


20:39:12.791212 IP 127.0.0.1.8777 > 127.0.0.1.50866: Flags [F.], seq 221, ack 296, win 40830, options [nop,nop,TS val 218887173 ecr 218887173], length 0
	0x0000:  4500 0034 a7a6 4000 4006 0000 7f00 0001  E..4..@.@.......
	0x0010:  7f00 0001 2249 c6b2 61b8 b371 fe0a 76bf  ...."I..a..q..v.
	0x0020:  8011 9f7e fe28 0000 0101 080a 0d0b f405  ...~.(..........
	0x0030:  0d0b f405                                ....
20:39:12.791226 IP 127.0.0.1.50866 > 127.0.0.1.8777: Flags [.], ack 222, win 40773, options [nop,nop,TS val 218887173 ecr 218887173], length 0
	0x0000:  4500 0034 36d3 4000 4006 0000 7f00 0001  E..46.@.@.......
	0x0010:  7f00 0001 c6b2 2249 fe0a 76bf 61b8 b372  ......"I..v.a..r
	0x0020:  8010 9f45 fe28 0000 0101 080a 0d0b f405  ...E.(..........
	0x0030:  0d0b f405                                ....
20:39:12.791257 IP 127.0.0.1.8777 > 127.0.0.1.50866: Flags [.], ack 296, win 40830, options [nop,nop,TS val 218887173 ecr 218887173], length 0
	0x0000:  4500 0034 6ac8 4000 4006 0000 7f00 0001  E..4j.@.@.......
	0x0010:  7f00 0001 2249 c6b2 61b8 b372 fe0a 76bf  ...."I..a..r..v.
	0x0020:  8010 9f7e fe28 0000 0101 080a 0d0b f405  ...~.(..........
	0x0030:  0d0b f405                                ....


Although HTTP protocol should NOT reuse the connection, here we see HttpClient send the next request on the same connection.
The server application code will never receive this request!


20:39:12.795330 IP 127.0.0.1.50866 > 127.0.0.1.8777: Flags [P.], seq 296:426, ack 222, win 40830, options [nop,nop,TS val 218887177 ecr 218887173], length 130
	0x0000:  4500 00b6 b1b5 4000 4006 0000 7f00 0001  E.....@.@.......
	0x0010:  7f00 0001 c6b2 2249 fe0a 76bf 61b8 b372  ......"I..v.a..r
	0x0020:  8018 9f7e feaa 0000 0101 080a 0d0b f409  ...~............
	0x0030:  0d0b f405 4745 5420 2f61 7574 6865 6e74  ....GET./authent
	0x0040:  6963 6174 6564 2e68 746d 6c20 4854 5450  icated.html.HTTP
	0x0050:  2f31 2e31 0d0a 486f 7374 3a20 3132 372e  /1.1..Host:.127.
	0x0060:  302e 302e 313a 3837 3737 0d0a 436f 6e6e  0.0.1:8777..Conn
	0x0070:  6563 7469 6f6e 3a20 4b65 6570 2d41 6c69  ection:.Keep-Ali
	0x0080:  7665 0d0a 5573 6572 2d41 6765 6e74 3a20  ve..User-Agent:.
	0x0090:  4170 6163 6865 2d48 7474 7043 6c69 656e  Apache-HttpClien
	0x00a0:  742f 342e 322e 3420 286a 6176 6120 312e  t/4.2.4.(java.1.
	0x00b0:  3529 0d0a 0d0a                           5)....


The Server had already told the client that server has closed the connection. Yet the client still sends a new request.
The server responds with the TCP Reset bit. The server kernel has never delivered this last request to the server application!


20:39:12.795372 IP 127.0.0.1.8777 > 127.0.0.1.50866: Flags [R], seq 1639494514, win 0, length 0
	0x0000:  4500 0028 94ed 4000 4006 0000 7f00 0001  E..(..@.@.......
	0x0010:  7f00 0001 2249 c6b2 61b8 b372 0000 0000  ...."I..a..r....
	0x0020:  5004 0000 fe1c 0000                      P.......








--------------------------------

The same flow without authentication shows a well-behaving HttpClient which does not reuse the connection

20:49:40.647744 IP 127.0.0.1.50944 > 127.0.0.1.8777: Flags [S], seq 1968143964, win 65535, options [mss 16344,nop,wscale 3,nop,nop,TS val 219512758 ecr 0,sackOK,eol], length 0
	0x0000:  4500 0040 bd64 4000 4006 0000 7f00 0001  E..@.d@.@.......
	0x0010:  7f00 0001 c700 2249 754f 7e5c 0000 0000  ......"IuO~\....
	0x0020:  b002 ffff fe34 0000 0204 3fd8 0103 0303  .....4....?.....
	0x0030:  0101 080a 0d15 7fb6 0000 0000 0402 0000  ................
20:49:40.647813 IP 127.0.0.1.8777 > 127.0.0.1.50944: Flags [S.], seq 967349206, ack 1968143965, win 65535, options [mss 16344,nop,wscale 3,nop,nop,TS val 219512758 ecr 219512758,sackOK,eol], length 0
	0x0000:  4500 0040 bc4b 4000 4006 0000 7f00 0001  E..@.K@.@.......
	0x0010:  7f00 0001 2249 c700 39a8 93d6 754f 7e5d  ...."I..9...uO~]
	0x0020:  b012 ffff fe34 0000 0204 3fd8 0103 0303  .....4....?.....
	0x0030:  0101 080a 0d15 7fb6 0d15 7fb6 0402 0000  ................
20:49:40.647823 IP 127.0.0.1.50944 > 127.0.0.1.8777: Flags [.], ack 1, win 65535, options [nop,nop,TS val 219512758 ecr 219512758], length 0
	0x0000:  4500 0034 516f 4000 4006 0000 7f00 0001  E..4Qo@.@.......
	0x0010:  7f00 0001 c700 2249 754f 7e5d 39a8 93d7  ......"IuO~]9...
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fb6  .....(..........
	0x0030:  0d15 7fb6                                ....
20:49:40.647833 IP 127.0.0.1.8777 > 127.0.0.1.50944: Flags [.], ack 1, win 65535, options [nop,nop,TS val 219512758 ecr 219512758], length 0
	0x0000:  4500 0034 7a46 4000 4006 0000 7f00 0001  E..4zF@.@.......
	0x0010:  7f00 0001 2249 c700 39a8 93d7 754f 7e5d  ...."I..9...uO~]
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fb6  .....(..........
	0x0030:  0d15 7fb6                                ....
20:49:40.684643 IP 127.0.0.1.50944 > 127.0.0.1.8777: Flags [P.], seq 1:135, ack 1, win 65535, options [nop,nop,TS val 219512794 ecr 219512758], length 134
	0x0000:  4500 00ba 0e05 4000 4006 0000 7f00 0001  E.....@.@.......
	0x0010:  7f00 0001 c700 2249 754f 7e5d 39a8 93d7  ......"IuO~]9...
	0x0020:  8018 ffff feae 0000 0101 080a 0d15 7fda  ................
	0x0030:  0d15 7fb6 4745 5420 2f6e 6f6e 2d61 7574  ....GET./non-aut
	0x0040:  6865 6e74 6963 6174 6564 2e68 746d 6c20  henticated.html.
	0x0050:  4854 5450 2f31 2e31 0d0a 486f 7374 3a20  HTTP/1.1..Host:.
	0x0060:  3132 372e 302e 302e 313a 3837 3737 0d0a  127.0.0.1:8777..
	0x0070:  436f 6e6e 6563 7469 6f6e 3a20 4b65 6570  Connection:.Keep
	0x0080:  2d41 6c69 7665 0d0a 5573 6572 2d41 6765  -Alive..User-Age
	0x0090:  6e74 3a20 4170 6163 6865 2d48 7474 7043  nt:.Apache-HttpC
	0x00a0:  6c69 656e 742f 342e 322e 3420 286a 6176  lient/4.2.4.(jav
	0x00b0:  6120 312e 3529 0d0a 0d0a                 a.1.5)....
20:49:40.684706 IP 127.0.0.1.8777 > 127.0.0.1.50944: Flags [.], ack 135, win 65535, options [nop,nop,TS val 219512794 ecr 219512794], length 0
	0x0000:  4500 0034 ed1d 4000 4006 0000 7f00 0001  E..4..@.@.......
	0x0010:  7f00 0001 2249 c700 39a8 93d7 754f 7ee3  ...."I..9...uO~.
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fda  .....(..........
	0x0030:  0d15 7fda                                ....
20:49:40.684898 IP 127.0.0.1.8777 > 127.0.0.1.50944: Flags [P.], seq 1:115, ack 135, win 65535, options [nop,nop,TS val 219512794 ecr 219512794], length 114
	0x0000:  4500 00a6 e32a 4000 4006 0000 7f00 0001  E....*@.@.......
	0x0010:  7f00 0001 2249 c700 39a8 93d7 754f 7ee3  ...."I..9...uO~.
	0x0020:  8018 ffff fe9a 0000 0101 080a 0d15 7fda  ................
	0x0030:  0d15 7fda 4854 5450 2f31 2e31 2032 3030  ....HTTP/1.1.200
	0x0040:  204f 4b20 2d20 636c 6965 6e74 2069 7320  .OK.-.client.is.
	0x0050:  3132 372e 302e 302e 313a 3530 3934 340d  127.0.0.1:50944.
	0x0060:  0a0d 0a48 5454 502f 312e 3120 3430 3020  ...HTTP/1.1.400.
	0x0070:  5468 6973 2069 7320 6120 7265 7175 6573  This.is.a.reques
	0x0080:  7420 626f 6479 202d 2063 6c69 656e 7420  t.body.-.client.
	0x0090:  6973 2031 3237 2e30 2e30 2e31 3a35 3039  is.127.0.0.1:509
	0x00a0:  3434 0d0a 0d0a                           44....
20:49:40.684912 IP 127.0.0.1.50944 > 127.0.0.1.8777: Flags [.], ack 115, win 65535, options [nop,nop,TS val 219512794 ecr 219512794], length 0
	0x0000:  4500 0034 9028 4000 4006 0000 7f00 0001  E..4.(@.@.......
	0x0010:  7f00 0001 c700 2249 754f 7ee3 39a8 9449  ......"IuO~.9..I
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fda  .....(..........
	0x0030:  0d15 7fda                                ....
20:49:40.684945 IP 127.0.0.1.8777 > 127.0.0.1.50944: Flags [F.], seq 115, ack 135, win 65535, options [nop,nop,TS val 219512794 ecr 219512794], length 0
	0x0000:  4500 0034 9760 4000 4006 0000 7f00 0001  E..4.`@.@.......
	0x0010:  7f00 0001 2249 c700 39a8 9449 754f 7ee3  ...."I..9..IuO~.
	0x0020:  8011 ffff fe28 0000 0101 080a 0d15 7fda  .....(..........
	0x0030:  0d15 7fda                                ....
20:49:40.684961 IP 127.0.0.1.50944 > 127.0.0.1.8777: Flags [.], ack 116, win 65535, options [nop,nop,TS val 219512794 ecr 219512794], length 0
	0x0000:  4500 0034 735f 4000 4006 0000 7f00 0001  E..4s_@.@.......
	0x0010:  7f00 0001 c700 2249 754f 7ee3 39a8 944a  ......"IuO~.9..J
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fda  .....(..........
	0x0030:  0d15 7fda                                ....
20:49:40.684968 IP 127.0.0.1.8777 > 127.0.0.1.50944: Flags [.], ack 135, win 65535, options [nop,nop,TS val 219512794 ecr 219512794], length 0
	0x0000:  4500 0034 5744 4000 4006 0000 7f00 0001  E..4WD@.@.......
	0x0010:  7f00 0001 2249 c700 39a8 944a 754f 7ee3  ...."I..9..JuO~.
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fda  .....(..........
	0x0030:  0d15 7fda                                ....
20:49:40.692920 IP 127.0.0.1.50944 > 127.0.0.1.8777: Flags [F.], seq 135, ack 116, win 65535, options [nop,nop,TS val 219512802 ecr 219512794], length 0
	0x0000:  4500 0034 da45 4000 4006 0000 7f00 0001  E..4.E@.@.......
	0x0010:  7f00 0001 c700 2249 754f 7ee3 39a8 944a  ......"IuO~.9..J
	0x0020:  8011 ffff fe28 0000 0101 080a 0d15 7fe2  .....(..........
	0x0030:  0d15 7fda                                ....
20:49:40.692969 IP 127.0.0.1.8777 > 127.0.0.1.50944: Flags [.], ack 136, win 65535, options [nop,nop,TS val 219512802 ecr 219512802], length 0
	0x0000:  4500 0034 9f40 4000 4006 0000 7f00 0001  E..4.@@.@.......
	0x0010:  7f00 0001 2249 c700 39a8 944a 754f 7ee4  ...."I..9..JuO~.
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fe2  .....(..........
	0x0030:  0d15 7fe2                                ....
20:49:40.693664 IP 127.0.0.1.50945 > 127.0.0.1.8777: Flags [S], seq 3021102219, win 65535, options [mss 16344,nop,wscale 3,nop,nop,TS val 219512802 ecr 0,sackOK,eol], length 0
	0x0000:  4500 0040 fc70 4000 4006 0000 7f00 0001  E..@.p@.@.......
	0x0010:  7f00 0001 c701 2249 b412 5c8b 0000 0000  ......"I..\.....
	0x0020:  b002 ffff fe34 0000 0204 3fd8 0103 0303  .....4....?.....
	0x0030:  0101 080a 0d15 7fe2 0000 0000 0402 0000  ................
20:49:40.693717 IP 127.0.0.1.8777 > 127.0.0.1.50945: Flags [S.], seq 1401392165, ack 3021102220, win 65535, options [mss 16344,nop,wscale 3,nop,nop,TS val 219512802 ecr 219512802,sackOK,eol], length 0
	0x0000:  4500 0040 c445 4000 4006 0000 7f00 0001  E..@.E@.@.......
	0x0010:  7f00 0001 2249 c701 5387 8c25 b412 5c8c  ...."I..S..%..\.
	0x0020:  b012 ffff fe34 0000 0204 3fd8 0103 0303  .....4....?.....
	0x0030:  0101 080a 0d15 7fe2 0d15 7fe2 0402 0000  ................
20:49:40.693727 IP 127.0.0.1.50945 > 127.0.0.1.8777: Flags [.], ack 1, win 65535, options [nop,nop,TS val 219512802 ecr 219512802], length 0
	0x0000:  4500 0034 584e 4000 4006 0000 7f00 0001  E..4XN@.@.......
	0x0010:  7f00 0001 c701 2249 b412 5c8c 5387 8c26  ......"I..\.S..&
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fe2  .....(..........
	0x0030:  0d15 7fe2                                ....
20:49:40.693737 IP 127.0.0.1.8777 > 127.0.0.1.50945: Flags [.], ack 1, win 65535, options [nop,nop,TS val 219512802 ecr 219512802], length 0
	0x0000:  4500 0034 221a 4000 4006 0000 7f00 0001  E..4".@.@.......
	0x0010:  7f00 0001 2249 c701 5387 8c26 b412 5c8c  ...."I..S..&..\.
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fe2  .....(..........
	0x0030:  0d15 7fe2                                ....
20:49:40.694338 IP 127.0.0.1.50945 > 127.0.0.1.8777: Flags [P.], seq 1:135, ack 1, win 65535, options [nop,nop,TS val 219512803 ecr 219512802], length 134
	0x0000:  4500 00ba 7b37 4000 4006 0000 7f00 0001  E...{7@.@.......
	0x0010:  7f00 0001 c701 2249 b412 5c8c 5387 8c26  ......"I..\.S..&
	0x0020:  8018 ffff feae 0000 0101 080a 0d15 7fe3  ................
	0x0030:  0d15 7fe2 4745 5420 2f6e 6f6e 2d61 7574  ....GET./non-aut
	0x0040:  6865 6e74 6963 6174 6564 2e68 746d 6c20  henticated.html.
	0x0050:  4854 5450 2f31 2e31 0d0a 486f 7374 3a20  HTTP/1.1..Host:.
	0x0060:  3132 372e 302e 302e 313a 3837 3737 0d0a  127.0.0.1:8777..
	0x0070:  436f 6e6e 6563 7469 6f6e 3a20 4b65 6570  Connection:.Keep
	0x0080:  2d41 6c69 7665 0d0a 5573 6572 2d41 6765  -Alive..User-Age
	0x0090:  6e74 3a20 4170 6163 6865 2d48 7474 7043  nt:.Apache-HttpC
	0x00a0:  6c69 656e 742f 342e 322e 3420 286a 6176  lient/4.2.4.(jav
	0x00b0:  6120 312e 3529 0d0a 0d0a                 a.1.5)....
20:49:40.694358 IP 127.0.0.1.8777 > 127.0.0.1.50945: Flags [.], ack 135, win 65535, options [nop,nop,TS val 219512803 ecr 219512803], length 0
	0x0000:  4500 0034 e455 4000 4006 0000 7f00 0001  E..4.U@.@.......
	0x0010:  7f00 0001 2249 c701 5387 8c26 b412 5d12  ...."I..S..&..].
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fe3  .....(..........
	0x0030:  0d15 7fe3                                ....
20:49:40.694758 IP 127.0.0.1.8777 > 127.0.0.1.50945: Flags [P.], seq 1:115, ack 135, win 65535, options [nop,nop,TS val 219512803 ecr 219512803], length 114
	0x0000:  4500 00a6 2d55 4000 4006 0000 7f00 0001  E...-U@.@.......
	0x0010:  7f00 0001 2249 c701 5387 8c26 b412 5d12  ...."I..S..&..].
	0x0020:  8018 ffff fe9a 0000 0101 080a 0d15 7fe3  ................
	0x0030:  0d15 7fe3 4854 5450 2f31 2e31 2032 3030  ....HTTP/1.1.200
	0x0040:  204f 4b20 2d20 636c 6965 6e74 2069 7320  .OK.-.client.is.
	0x0050:  3132 372e 302e 302e 313a 3530 3934 350d  127.0.0.1:50945.
	0x0060:  0a0d 0a48 5454 502f 312e 3120 3430 3020  ...HTTP/1.1.400.
	0x0070:  5468 6973 2069 7320 6120 7265 7175 6573  This.is.a.reques
	0x0080:  7420 626f 6479 202d 2063 6c69 656e 7420  t.body.-.client.
	0x0090:  6973 2031 3237 2e30 2e30 2e31 3a35 3039  is.127.0.0.1:509
	0x00a0:  3435 0d0a 0d0a                           45....
20:49:40.694776 IP 127.0.0.1.50945 > 127.0.0.1.8777: Flags [.], ack 115, win 65535, options [nop,nop,TS val 219512803 ecr 219512803], length 0
	0x0000:  4500 0034 9b29 4000 4006 0000 7f00 0001  E..4.)@.@.......
	0x0010:  7f00 0001 c701 2249 b412 5d12 5387 8c98  ......"I..].S...
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fe3  .....(..........
	0x0030:  0d15 7fe3                                ....
20:49:40.694789 IP 127.0.0.1.8777 > 127.0.0.1.50945: Flags [F.], seq 115, ack 135, win 65535, options [nop,nop,TS val 219512803 ecr 219512803], length 0
	0x0000:  4500 0034 cd0e 4000 4006 0000 7f00 0001  E..4..@.@.......
	0x0010:  7f00 0001 2249 c701 5387 8c98 b412 5d12  ...."I..S.....].
	0x0020:  8011 ffff fe28 0000 0101 080a 0d15 7fe3  .....(..........
	0x0030:  0d15 7fe3                                ....
20:49:40.694803 IP 127.0.0.1.8777 > 127.0.0.1.50945: Flags [F.], seq 115, ack 135, win 65535, options [nop,nop,TS val 219512803 ecr 219512803], length 0
	0x0000:  4500 0034 4174 4000 4006 0000 7f00 0001  E..4At@.@.......
	0x0010:  7f00 0001 2249 c701 5387 8c98 b412 5d12  ...."I..S.....].
	0x0020:  8011 ffff fe28 0000 0101 080a 0d15 7fe3  .....(..........
	0x0030:  0d15 7fe3                                ....
20:49:40.694811 IP 127.0.0.1.50945 > 127.0.0.1.8777: Flags [.], ack 116, win 65535, options [nop,nop,TS val 219512803 ecr 219512803], length 0
	0x0000:  4500 0034 cd38 4000 4006 0000 7f00 0001  E..4.8@.@.......
	0x0010:  7f00 0001 c701 2249 b412 5d12 5387 8c99  ......"I..].S...
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fe3  .....(..........
	0x0030:  0d15 7fe3                                ....
20:49:40.694816 IP 127.0.0.1.50945 > 127.0.0.1.8777: Flags [.], ack 116, win 65535, options [nop,nop,TS val 219512803 ecr 219512803], length 0
	0x0000:  4500 0034 6b7a 4000 4006 0000 7f00 0001  E..4kz@.@.......
	0x0010:  7f00 0001 c701 2249 b412 5d12 5387 8c99  ......"I..].S...
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fe3  .....(..........
	0x0030:  0d15 7fe3                                ....
20:49:40.694823 IP 127.0.0.1.8777 > 127.0.0.1.50945: Flags [.], ack 135, win 65535, options [nop,nop,TS val 219512803 ecr 219512803], length 0
	0x0000:  4500 0034 e028 4000 4006 0000 7f00 0001  E..4.(@.@.......
	0x0010:  7f00 0001 2249 c701 5387 8c99 b412 5d12  ...."I..S.....].
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fe3  .....(..........
	0x0030:  0d15 7fe3                                ....
20:49:40.695039 IP 127.0.0.1.50945 > 127.0.0.1.8777: Flags [F.], seq 135, ack 116, win 65535, options [nop,nop,TS val 219512803 ecr 219512803], length 0
	0x0000:  4500 0034 980c 4000 4006 0000 7f00 0001  E..4..@.@.......
	0x0010:  7f00 0001 c701 2249 b412 5d12 5387 8c99  ......"I..].S...
	0x0020:  8011 ffff fe28 0000 0101 080a 0d15 7fe3  .....(..........
	0x0030:  0d15 7fe3                                ....
20:49:40.695056 IP 127.0.0.1.8777 > 127.0.0.1.50945: Flags [.], ack 136, win 65535, options [nop,nop,TS val 219512803 ecr 219512803], length 0
	0x0000:  4500 0034 dd73 4000 4006 0000 7f00 0001  E..4.s@.@.......
	0x0010:  7f00 0001 2249 c701 5387 8c99 b412 5d13  ...."I..S.....].
	0x0020:  8010 ffff fe28 0000 0101 080a 0d15 7fe3  .....(..........
	0x0030:  0d15 7fe3                                ....



                  
> HttpClient incorrectly reuses HTTP/1.1 connection - the response body of the first request is considered as the response for the second request
> -----------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPCLIENT-1376
>                 URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1376
>             Project: HttpComponents HttpClient
>          Issue Type: Bug
>    Affects Versions: 4.2.4
>            Reporter: Carl D'Halluin
>
> In the following scenario, the HttpClient incorrectly reuses the HTTP/1.1 stream, and actually considers the response body of the first request, to be the HTTP response to a second request.
> Details:
> 1. Client does a simple HTTP/1.1 GET request
> 2. Server responds with a 401 and a WWW-Authenticate header
> 3. Client repeats the GET request but now with an Authorization header
> 4. Server responds with a HTTP/1.1 200 OK but there is no content length. The server sends a response body
> 5. HttpClient ignores the response body by closing the entity content InputStream (or call EntityUtils.consume)
> 6. Client sends a new HTTP/1.1 GET request (totally unrelated to the previous one)
> 7. Client erroneously considers the response body received in step 5 as the response to step 6
> I tracked the bug down in the HttpClient library: Step 2 marks the HTTP connection as reusable. Step 4 should explicitly mark the connection as non-reusable since the only thing the client can do to such an ugly reponse (no content-length) is read until EOF. However, that does not happen in step 4. Hence in step 5 the code sees that the connection is reusable, and doesnt bother consuming the response content at all. The body is reused in step 7
> Here we see 4 times 2 subsequent request
> - first 2 are no authentication no streaming: HttpClient correctly does not reuse connection (see port number)
> - next 2 are no authentication with streaming: HttpClient correctly does not reuse connection
> - next 2 are with authentication with streaming: HttpClient correctly does not reuse connection
> - final 2 are with authentication no streaming: Bug - HttpClient tries to reuse connection given error. Closing the HttpResponse InputStream does not correctly close the underlying Socket
> {code}
> REQUEST: GET http://127.0.0.1:8777/non-authenticated.html
> RESPONSE STATUS: HTTP/1.1 200 OK - client is 127.0.0.1:49603
> RESPONSE BODY - SKIPPED
> REQUEST: GET http://127.0.0.1:8777/non-authenticated.html
> RESPONSE STATUS: HTTP/1.1 200 OK - client is 127.0.0.1:49604
> RESPONSE BODY - SKIPPED
> =======================
> REQUEST: GET http://127.0.0.1:8777/non-authenticated.html
> RESPONSE STATUS: HTTP/1.1 200 OK - client is 127.0.0.1:49605
> RESPONSE BODY:   HTTP/1.1 400 This is a request body - client is 127.0.0.1:49605
> RESPONSE BODY:   
> REQUEST: GET http://127.0.0.1:8777/non-authenticated.html
> RESPONSE STATUS: HTTP/1.1 200 OK - client is 127.0.0.1:49606
> RESPONSE BODY:   HTTP/1.1 400 This is a request body - client is 127.0.0.1:49606
> RESPONSE BODY:   
> =======================
> REQUEST: GET http://127.0.0.1:8777/authenticated.html
> RESPONSE STATUS: HTTP/1.1 200 OK - client is 127.0.0.1:49607
> RESPONSE BODY:   HTTP/1.1 400 This is a request body - client is 127.0.0.1:49607
> RESPONSE BODY:   
> REQUEST: GET http://127.0.0.1:8777/authenticated.html
> RESPONSE STATUS: HTTP/1.1 200 OK - client is 127.0.0.1:49608
> RESPONSE BODY:   HTTP/1.1 400 This is a request body - client is 127.0.0.1:49608
> RESPONSE BODY:   
> =======================
> REQUEST: GET http://127.0.0.1:8777/authenticated.html
> RESPONSE STATUS: HTTP/1.1 200 OK - client is 127.0.0.1:49609
> RESPONSE BODY - SKIPPED
> REQUEST: GET http://127.0.0.1:8777/authenticated.html
> RESPONSE STATUS: HTTP/1.1 400 This is a request body - client is 127.0.0.1:49609
> --> BUG! Response status 400
> RESPONSE BODY - SKIPPED
> {code}

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message