JDK-8012625 : Incorrect handling of HTTP/1.1 " Expect: 100-continue " in HttpURLConnection
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7,7u21,8
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: linux_ubuntu
  • Submitted: 2013-04-18
  • Updated: 2024-01-19
  • Resolved: 2013-05-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7 JDK 8
7u80Fixed 8 b91Fixed
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version  " 1.7.0_21 " 
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux laptop-hp 3.5.0-27-generic #46-Ubuntu SMP Mon Mar 25 19:58:17 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
sun.net.www.protocol.http.HttpURLConnection handles 'Expect: 100-continue' header incorrectly for HTTP POST requests with the Expect headers set according to HTTP/1.1 spec: http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.3

It causes 5 seconds delays for all HTTP POST request setting Expect: 100-continue header.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Open HttpURLConnection (e.g. through new URL( " http://... " ).openConnection) and setup the HTTP connection to use POST method and add HTTP/1.1 Expect 100-continue header:

httpConnection.setRequestMethod( " POST " );
httpConnection.setRequestProperty( " Expect " ,  " 100-continue " );

When httpConnection.getOutputStream() is called, sun.net.www.protocol.http.HttpURLConnection.getOutputStream() implementation first checks if the request has Expect header set to 100-continue. If it does, it first waits for the server for either HTTP 100 (continue) or HTTP 417 (expectation failed) response before even sending request headers (as required by HTTP/1.1 spec: http://www.w3.org/Protocols/rfc2616/rfc2616-sec8.html#sec8.2.3).

As the server doesn't know the client waits for HTTP100 or HTTP417, the client always waits full 5 seconds for the server response (sun.net.www.protocol.http.HttpURLConnection.expect100Continue()).

The 5 seconds delay occurs in all HTTP POST requests which set Expect: 100-continue header.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
If the HTTP request contains Expect: 100-continue header, HttpURLConnection should first send HTTP headers and then call sun.net.www.protocol.http.HttpURLConnection.expect100Continue() method.
ACTUAL -
When HTTP request is setup as in the attached test case, sun.net.www.protocol.http.HttpURLConnection.getOutputStream() calls expect100Continue() before sending HTTP headers which is incorrect.

ERROR MESSAGES/STACK TRACES THAT OCCUR :
As there is no way to attach files, I'm including output from my test case:
1366278397: Calling connect()
1366278397: Calling getOutputStream()...
1366278402: Starting to write body...
1366278402: Flushed and closed output stream
1366278402: Waiting for response code...
1366278402: Received response code: 200

I am also attaching output from wireshark capture (truncated after relevant part) which shows that there is a 5 seconds delay after the connection is opened and before HTTP headers are sent:

No.     Time           Source                Destination           Protocol Length Info
      3 0.448098000    127.0.0.1             127.0.0.1             TCP      74     52644 > http-alt [SYN] Seq=0 Win=32792 Len=0 MSS=16396 SACK_PERM=1 TSval=45328827 TSecr=0 WS=128

Frame 3: 74 bytes on wire (592 bits), 74 bytes captured (592 bits) on interface 0
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol Version 4, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 (127.0.0.1)
Transmission Control Protocol, Src Port: 52644 (52644), Dst Port: http-alt (8080), Seq: 0, Len: 0

0000  00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00   ..............E.
0010  00 3c cd cf 40 00 40 06 6e ea 7f 00 00 01 7f 00   .<..@.@.n.......
0020  00 01 cd a4 1f 90 09 8e 64 74 00 00 00 00 a0 02   ........dt......
0030  80 18 fe 30 00 00 02 04 40 0c 04 02 08 0a 02 b3   ...0....@.......
0040  a9 bb 00 00 00 00 01 03 03 07                     ..........

No.     Time           Source                Destination           Protocol Length Info
      4 0.448110000    127.0.0.1             127.0.0.1             TCP      74     http-alt > 52644 [SYN, ACK] Seq=0 Ack=1 Win=32768 Len=0 MSS=16396 SACK_PERM=1 TSval=45328827 TSecr=45328827 WS=128

Frame 4: 74 bytes on wire (592 bits), 74 bytes captured (592 bits) on interface 0
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol Version 4, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 (127.0.0.1)
Transmission Control Protocol, Src Port: http-alt (8080), Dst Port: 52644 (52644), Seq: 0, Ack: 1, Len: 0

0000  00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00   ..............E.
0010  00 3c 00 00 40 00 40 06 3c ba 7f 00 00 01 7f 00   .<..@.@.<.......
0020  00 01 1f 90 cd a4 dd 1a 37 17 09 8e 64 75 a0 12   ........7...du..
0030  80 00 fe 30 00 00 02 04 40 0c 04 02 08 0a 02 b3   ...0....@.......
0040  a9 bb 02 b3 a9 bb 01 03 03 07                     ..........

No.     Time           Source                Destination           Protocol Length Info
      5 0.448120000    127.0.0.1             127.0.0.1             TCP      66     52644 > http-alt [ACK] Seq=1 Ack=1 Win=32896 Len=0 TSval=45328827 TSecr=45328827

Frame 5: 66 bytes on wire (528 bits), 66 bytes captured (528 bits) on interface 0
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol Version 4, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 (127.0.0.1)
Transmission Control Protocol, Src Port: 52644 (52644), Dst Port: http-alt (8080), Seq: 1, Ack: 1, Len: 0

0000  00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00   ..............E.
0010  00 34 cd d0 40 00 40 06 6e f1 7f 00 00 01 7f 00   .4..@.@.n.......
0020  00 01 cd a4 1f 90 09 8e 64 75 dd 1a 37 18 80 10   ........du..7...
0030  01 01 fe 28 00 00 01 01 08 0a 02 b3 a9 bb 02 b3   ...(............
0040  a9 bb                                             ..

No.     Time           Source                Destination           Protocol Length Info
     20 5.453169000    127.0.0.1             127.0.0.1             TCP      369    [TCP segment of a reassembled PDU]

Frame 20: 369 bytes on wire (2952 bits), 369 bytes captured (2952 bits) on interface 0
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol Version 4, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 (127.0.0.1)
Transmission Control Protocol, Src Port: 52644 (52644), Dst Port: http-alt (8080), Seq: 1, Ack: 1, Len: 303

0000  00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00   ..............E.
0010  01 63 cd d1 40 00 40 06 6d c1 7f 00 00 01 7f 00   .c..@.@.m.......
0020  00 01 cd a4 1f 90 09 8e 64 75 dd 1a 37 18 80 18   ........du..7...
0030  01 01 ff 57 00 00 01 01 08 0a 02 b3 ae 9e 02 b3   ...W............
0040  a9 bb 50 4f 53 54 20 2f 20 48 54 54 50 2f 31 2e   ..POST / HTTP/1.
0050  31 0d 0a 45 78 70 65 63 74 3a 20 31 30 30 2d 63   1..Expect: 100-c
0060  6f 6e 74 69 6e 75 65 0d 0a 48 65 6c 6c 6f 3a 20   ontinue..Hello:
0070  57 6f 72 6c 64 21 0d 0a 43 61 63 68 65 2d 43 6f   World!..Cache-Co
0080  6e 74 72 6f 6c 3a 20 6e 6f 2d 63 61 63 68 65 0d   ntrol: no-cache.
0090  0a 50 72 61 67 6d 61 3a 20 6e 6f 2d 63 61 63 68   .Pragma: no-cach
00a0  65 0d 0a 55 73 65 72 2d 41 67 65 6e 74 3a 20 4a   e..User-Agent: J
00b0  61 76 61 2f 31 2e 37 2e 30 5f 32 31 0d 0a 48 6f   ava/1.7.0_21..Ho
00c0  73 74 3a 20 6c 6f 63 61 6c 68 6f 73 74 3a 38 30   st: localhost:80
00d0  38 30 0d 0a 41 63 63 65 70 74 3a 20 74 65 78 74   80..Accept: text
00e0  2f 68 74 6d 6c 2c 20 69 6d 61 67 65 2f 67 69 66   /html, image/gif
00f0  2c 20 69 6d 61 67 65 2f 6a 70 65 67 2c 20 2a 3b   , image/jpeg, *;
0100  20 71 3d 2e 32 2c 20 2a 2f 2a 3b 20 71 3d 2e 32    q=.2, */*; q=.2
0110  0d 0a 43 6f 6e 6e 65 63 74 69 6f 6e 3a 20 6b 65   ..Connection: ke
0120  65 70 2d 61 6c 69 76 65 0d 0a 43 6f 6e 74 65 6e   ep-alive..Conten
0130  74 2d 74 79 70 65 3a 20 61 70 70 6c 69 63 61 74   t-type: applicat
0140  69 6f 6e 2f 78 2d 77 77 77 2d 66 6f 72 6d 2d 75   ion/x-www-form-u
0150  72 6c 65 6e 63 6f 64 65 64 0d 0a 43 6f 6e 74 65   rlencoded..Conte
0160  6e 74 2d 4c 65 6e 67 74 68 3a 20 31 32 0d 0a 0d   nt-Length: 12...
0170  0a                                                .

No.     Time           Source                Destination           Protocol Length Info
     21 5.453194000    127.0.0.1             127.0.0.1             TCP      66     http-alt > 52644 [ACK] Seq=1 Ack=304 Win=32768 Len=0 TSval=45330078 TSecr=45330078

Frame 21: 66 bytes on wire (528 bits), 66 bytes captured (528 bits) on interface 0
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol Version 4, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 (127.0.0.1)
Transmission Control Protocol, Src Port: http-alt (8080), Dst Port: 52644 (52644), Seq: 1, Ack: 304, Len: 0

0000  00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00   ..............E.
0010  00 34 9e a3 40 00 40 06 9e 1e 7f 00 00 01 7f 00   .4..@.@.........
0020  00 01 1f 90 cd a4 dd 1a 37 18 09 8e 65 a4 80 10   ........7...e...
0030  01 00 fe 28 00 00 01 01 08 0a 02 b3 ae 9e 02 b3   ...(............
0040  ae 9e                                             ..

No.     Time           Source                Destination           Protocol Length Info
     22 5.453718000    127.0.0.1             127.0.0.1             HTTP     91     HTTP/1.1 100 Continue

Frame 22: 91 bytes on wire (728 bits), 91 bytes captured (728 bits) on interface 0
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol Version 4, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 (127.0.0.1)
Transmission Control Protocol, Src Port: http-alt (8080), Dst Port: 52644 (52644), Seq: 1, Ack: 304, Len: 25
Hypertext Transfer Protocol

0000  00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00   ..............E.
0010  00 4d 9e a4 40 00 40 06 9e 04 7f 00 00 01 7f 00   .M..@.@.........
0020  00 01 1f 90 cd a4 dd 1a 37 18 09 8e 65 a4 80 18   ........7...e...
0030  01 00 fe 41 00 00 01 01 08 0a 02 b3 ae 9e 02 b3   ...A............
0040  ae 9e 48 54 54 50 2f 31 2e 31 20 31 30 30 20 43   ..HTTP/1.1 100 C
0050  6f 6e 74 69 6e 75 65 0d 0a 0d 0a                  ontinue....

No.     Time           Source                Destination           Protocol Length Info
     23 5.453788000    127.0.0.1             127.0.0.1             TCP      66     52644 > http-alt [ACK] Seq=304 Ack=26 Win=32896 Len=0 TSval=45330078 TSecr=45330078

Frame 23: 66 bytes on wire (528 bits), 66 bytes captured (528 bits) on interface 0
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol Version 4, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 (127.0.0.1)
Transmission Control Protocol, Src Port: 52644 (52644), Dst Port: http-alt (8080), Seq: 304, Ack: 26, Len: 0

0000  00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00   ..............E.
0010  00 34 cd d2 40 00 40 06 6e ef 7f 00 00 01 7f 00   .4..@.@.n.......
0020  00 01 cd a4 1f 90 09 8e 65 a4 dd 1a 37 31 80 10   ........e...71..
0030  01 01 fe 28 00 00 01 01 08 0a 02 b3 ae 9e 02 b3   ...(............
0040  ae 9e                                             ..

No.     Time           Source                Destination           Protocol Length Info
     24 5.453828000    127.0.0.1             127.0.0.1             HTTP     78     POST / HTTP/1.1  (application/x-www-form-urlencoded)

Frame 24: 78 bytes on wire (624 bits), 78 bytes captured (624 bits) on interface 0
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol Version 4, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 (127.0.0.1)
Transmission Control Protocol, Src Port: 52644 (52644), Dst Port: http-alt (8080), Seq: 304, Ack: 26, Len: 12
[2 Reassembled TCP Segments (315 bytes): #20(303), #24(12)]
Hypertext Transfer Protocol
Line-based text data: application/x-www-form-urlencoded

Frame (78 bytes):

0000  00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00   ..............E.
0010  00 40 cd d3 40 00 40 06 6e e2 7f 00 00 01 7f 00   .@..@.@.n.......
0020  00 01 cd a4 1f 90 09 8e 65 a4 dd 1a 37 31 80 18   ........e...71..
0030  01 01 fe 34 00 00 01 01 08 0a 02 b3 ae 9e 02 b3   ...4............
0040  ae 9e 48 6f 77 20 61 72 65 20 79 6f 75 3f         ..How are you?

Reassembled TCP (315 bytes):

0000  50 4f 53 54 20 2f 20 48 54 54 50 2f 31 2e 31 0d   POST / HTTP/1.1.
0010  0a 45 78 70 65 63 74 3a 20 31 30 30 2d 63 6f 6e   .Expect: 100-con
0020  74 69 6e 75 65 0d 0a 48 65 6c 6c 6f 3a 20 57 6f   tinue..Hello: Wo
0030  72 6c 64 21 0d 0a 43 61 63 68 65 2d 43 6f 6e 74   rld!..Cache-Cont
0040  72 6f 6c 3a 20 6e 6f 2d 63 61 63 68 65 0d 0a 50   rol: no-cache..P
0050  72 61 67 6d 61 3a 20 6e 6f 2d 63 61 63 68 65 0d   ragma: no-cache.
0060  0a 55 73 65 72 2d 41 67 65 6e 74 3a 20 4a 61 76   .User-Agent: Jav
0070  61 2f 31 2e 37 2e 30 5f 32 31 0d 0a 48 6f 73 74   a/1.7.0_21..Host
0080  3a 20 6c 6f 63 61 6c 68 6f 73 74 3a 38 30 38 30   : localhost:8080
0090  0d 0a 41 63 63 65 70 74 3a 20 74 65 78 74 2f 68   ..Accept: text/h
00a0  74 6d 6c 2c 20 69 6d 61 67 65 2f 67 69 66 2c 20   tml, image/gif,
00b0  69 6d 61 67 65 2f 6a 70 65 67 2c 20 2a 3b 20 71   image/jpeg, *; q
00c0  3d 2e 32 2c 20 2a 2f 2a 3b 20 71 3d 2e 32 0d 0a   =.2, */*; q=.2..
00d0  43 6f 6e 6e 65 63 74 69 6f 6e 3a 20 6b 65 65 70   Connection: keep
00e0  2d 61 6c 69 76 65 0d 0a 43 6f 6e 74 65 6e 74 2d   -alive..Content-
00f0  74 79 70 65 3a 20 61 70 70 6c 69 63 61 74 69 6f   type: applicatio
0100  6e 2f 78 2d 77 77 77 2d 66 6f 72 6d 2d 75 72 6c   n/x-www-form-url
0110  65 6e 63 6f 64 65 64 0d 0a 43 6f 6e 74 65 6e 74   encoded..Content
0120  2d 4c 65 6e 67 74 68 3a 20 31 32 0d 0a 0d 0a 48   -Length: 12....H
0130  6f 77 20 61 72 65 20 79 6f 75 3f                  ow are you?

No.     Time           Source                Destination           Protocol Length Info
     25 5.455862000    127.0.0.1             127.0.0.1             TCP      9066   [TCP segment of a reassembled PDU]

Frame 25: 9066 bytes on wire (72528 bits), 9066 bytes captured (72528 bits) on interface 0
Ethernet II, Src: 00:00:00_00:00:00 (00:00:00:00:00:00), Dst: 00:00:00_00:00:00 (00:00:00:00:00:00)
Internet Protocol Version 4, Src: 127.0.0.1 (127.0.0.1), Dst: 127.0.0.1 (127.0.0.1)
Transmission Control Protocol, Src Port: http-alt (8080), Dst Port: 52644 (52644), Seq: 26, Ack: 316, Len: 9000

0000  00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00   ..............E.
0010  23 5c 9e a5 40 00 40 06 7a f4 7f 00 00 01 7f 00   #\..@.@.z.......
0020  00 01 1f 90 cd a4 dd 1a 37 31 09 8e 65 b0 80 18   ........71..e...
0030  01 00 21 51 00 00 01 01 08 0a 02 b3 ae 9f 02 b3   ..!Q............
0040  ae 9e 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f   ..HTTP/1.1 200 O
0050  4b 0d 0a 53 65 72 76 65 72 3a 20 41 70 61 63 68   K..Server: Apach
0060  65 2d 43 6f 79 6f 74 65 2f 31 2e 31 0d 0a 43 6f   e-Coyote/1.1..Co
0070  6e 74 65 6e 74 2d 54 79 70 65 3a 20 74 65 78 74   ntent-Type: text
0080  2f 68 74 6d 6c 3b 63 68 61 72 73 65 74 3d 49 53   /html;charset=IS
0090  4f 2d 38 38 35 39 2d 31 0d 0a 54 72 61 6e 73 66   O-8859-1..Transf
00a0  65 72 2d 45 6e 63 6f 64 69 6e 67 3a 20 63 68 75   er-Encoding: chu
00b0  6e 6b 65 64 0d 0a 44 61 74 65 3a 20 54 68 75 2c   nked..Date: Thu,
00c0  20 31 38 20 41 70 72 20 32 30 31 33 20 30 39 3a    18 Apr 2013 09:
00d0  34 36 3a 34 32 20 47 4d 54 0d 0a 0d 0a 32 30 30   46:42 GMT....200

REPRODUCIBILITY :
This bug can be reproduced always.

( This report has more than 16,000 characters and has been truncated. )
Comments
Looks worthwhile since fix seems straightforward
28-05-2014

should we fix in jdk7u ? I'll create a backport.
28-05-2014

Verified test: sun/net/www/protocol/http/B8012625.java http://aurora.ru.oracle.com/functional/faces/ChessBoard.xhtml?reportName=J2SEFailures&parameters=%5BtestNameFilterRegExp%5Dsun%2Fnet%2Fwww%2Fprotocol%2Fhttp%2FB8012625.java%5Bjdkproduct%5DJava%28TM%29%25%5Brelease%5D1.8.0%5Bbuild%5D%25%5Bvmproduct%5DJava%25VM%25%5Bvmrelease%5D%25%5Bvmbuild%5D%25%5Bcomponent%5D%25%5Btags%5D%25%5BstartDate%5DSep+10%2C+2009+1%3A00%3A00+AM+MSD%5BendDate%5DSep+10%2C+2020+1%3A00%3A00+AM+MSK%5BrunNames%5D%27%27%5BbatchNames%5D%27%27%5BbatchNameFilterRegExp%5D%25%5BrunNameFilterRegExp%5D%25%5BtestsuiteNameFilterRegExp%5D%25%5Bstatuses%5D%281%3D1%29%5Bmatches%5D%281%3D1%29%5Bbundles%5Dnone&splitting=%5BZ+axis%5D%5BY+axis%5Dfailure%2C+reason%2C+productConfiguration%2C+release%2C+build%2C+date%2C+buildType%5BX+axis%5Dos%2C+bitness%5BComplement%5Dvmrelease%2C+vmbuild%2C+VMVersionString%2C+JDKVersionString%2C+tags%2C+groups%2C+platform%2C+truncatedProductConfiguration%2C+VMMode%2C+JDKProfile%2C+VMFlavor%2C+hostname%2C+osFlavor%2C+osVersion%2C+buildDate%2C+msDate%2C+baseline%2C+emb_arch%2C+batch%2C+runName%2C+harness%2C+testbaseVersion%2C+testbase%2C+fullTestsuite%2C+testsuite%2C+component%2C+baselineName%2C+crs%2C+bugType%2C+duration&reference=%5BOthers%5Drelease%2C+build%2C+vmrelease%2C+vmbuild%2C+VMVersionString%2C+JDKVersionString%2C+tags%2C+groups%2C+platform%2C+truncatedProductConfiguration%2C+buildType%2C+bitness%2C+productConfiguration%2C+VMMode%2C+JDKProfile%2C+VMFlavor%2C+hostname%2C+os%2C+osFlavor%2C+osVersion%2C+date%2C+buildDate%2C+msDate%2C+baseline%2C+emb_arch%2C+batch%2C+runName%2C+harness%2C+testbaseVersion%2C+testbase%2C+fullTestsuite%2C+testsuite%2C+component%2C+baselineName%2C+failure%2C+reason%2C+crs%2C+bugType%2C+duration%5BReference+Set%5D&mixReference=false&flags=&significance=empty&hideDataConfiguration=true&calculateSummary=false&showSummaryExpanded=false&showSummaryContents=true&showComplementAttributes=false&compactTables=true&viewStyle=chessboard&filter_override=
07-01-2014

URL: http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/74f91b7f4b66 User: lana Date: 2013-05-21 18:20:30 +0000
21-05-2013

URL: http://hg.openjdk.java.net/jdk8/tl/jdk/rev/74f91b7f4b66 User: michaelm Date: 2013-05-16 16:32:31 +0000
16-05-2013

The original "support" for Expect: Continue in JDK (up to JDK 7) just about obeyed the protocol, but didn't really do what was intended, which was to delay sending the request body until the 100 response is received. Users might not have noticed this behavior especially in cases where the server was responding with the 100 quite quickly. In jdk7 we fixed this, but at the cost of requiring the calling app to use one of the request streaming modes. We inadvertently broke the original behavior though, So, for code that was setting this header, but not using streaming, they end up waiting 5 second for the 100 response, before the request proceeds. The fix seems to be quite simple: in s.n.w.h.p.HttpURLConnection @@ -1094,7 +1225,7 @@ boolean expectContinue = false; String expects = requests.findValue("Expect"); - if ("100-Continue".equalsIgnoreCase(expects)) { + if ("100-Continue".equalsIgnoreCase(expects) && streaming()) { http.setIgnoreContinue(false); expectContinue = true; }
14-05-2013

This is not a bug per say, but a limitation of the existing API. Expect: 100-continue is only supported with streaming requests, i.e. setChunkedStreamingMode(int), or setFixedLengthStreamingMode(long). With the above API's the appropriate header, content-length or Transfer-Encoding: chunked, can be set before return the OutputStream ( from getOutputStream() ). Without either of the above calls the content-length is only determinable after the returned output stream is closed, and this happens after the return from getOutptuStream(). So I would say this is a limitation of the API. But the workaround is quite straight forward, use streaming.
07-05-2013

This issue is present in JDK 7 FCS.
19-04-2013

Test case: ---------- BEGIN SOURCE ---------- import java.io.IOException; import java.io.OutputStream; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; public class Expect100ContinueTest { public static void main(String[] args) throws MalformedURLException, IOException { HttpURLConnection connection = (HttpURLConnection) new URL("http://www.google.com/test").openConnection(); connection.setRequestMethod("POST"); connection.setDoOutput(true); connection.setDoInput(true); connection.setUseCaches(false); connection.setRequestProperty("Expect", "100-continue"); connection.setRequestProperty("Hello", "World!"); log("Calling connect()"); connection.connect(); log("Calling getOutputStream()..."); OutputStream output = connection.getOutputStream(); log("Starting to write body..."); output.write("How are you?".getBytes("UTF-8")); output.flush(); output.close(); log("Flushed and closed output stream"); log("Waiting for response code..."); int responseCode = connection.getResponseCode(); log("Received response code: " + responseCode); } private static void log(String message) { System.out.println(System.currentTimeMillis()/1000 + ": " + message); } } ---------- END SOURCE ----------
18-04-2013