Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8012625

Incorrect handling of HTTP/1.1 " Expect: 100-continue " in HttpURLConnection

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 8
    • 7, 7u21, 8
    • core-libs
    • b91
    • linux_ubuntu

    Backports

      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. )

        Attachments

          Issue Links

            Activity

              People

                michaelm Michael McMahon
                webbuggrp Webbug Group
                Votes:
                0 Vote for this issue
                Watchers:
                7 Start watching this issue

                Dates

                  Created:
                  Updated:
                  Resolved: