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

setRequestProperty(key, null) results in HTTP header without colon in request

    Details

    • Subcomponent:
    • Resolved In Build:
      b10
    • CPU:
      generic
    • OS:
      generic

      Backports

        Description

        FULL PRODUCT VERSION :
        java version "1.8.0_131"
        Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
        Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows [Version 6.1.7601]

        A DESCRIPTION OF THE PROBLEM :
        If setRequestProperty method is called on HttpURLConnection object with non-empty "key" and "value" set to null, the corresponding HTTP header is inserted into the request, but without ":" (colon). The header name passed via "key" is directly followed by CR LF. This is violation of HTTP protocol, since colons in headers are mandatory.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Compile the included source code and run it passing any HTTP URL as a parameter and inspect network traffic with a sniffer. For example:

        java -cp . Test1 http://www.ya.ru

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        In no conditions an HTTP header without colon should ever be put into a request. Possible platform behavior for passed null as value of "value" argument may include:
        - Throwing NullPointerException (the preferred approach)
        - Adding a valid HTTP header with name passed in "key" argument and empty value. The colon MUST be present.
        - Not adding a header.
        ACTUAL -
        The following request is being generated and sent to the server for described example. Note the missing ":" in "MyHeader" header:

        GET / HTTP/1.1
        MyHeader
        User-Agent: Java/1.8.0_131
        Host: www.ya.ru
        Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
        Connection: keep-alive



        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.net.URL;
        import java.net.URLConnection;
        import java.net.MalformedURLException;
        import java.io.IOException;
        import java.io.BufferedReader;
        import java.io.InputStreamReader;

        class Test1 {
          public static void main(String[] asArguments) throws MalformedURLException, IOException {
            URL rURL = new URL(asArguments[0]);
            URLConnection rConnection = rURL.openConnection();
            rConnection.setRequestProperty("MyHeader", null);
            BufferedReader in = new BufferedReader(new InputStreamReader(rConnection.getInputStream()));
            String inputLine;
            while ((inputLine = in.readLine()) != null) System.out.println(inputLine);
            in.close();
          }
        }
        ---------- END SOURCE ----------

          Attachments

            Issue Links

              Activity

                People

                • Assignee:
                  michaelm Michael McMahon
                  Reporter:
                  webbuggrp Webbug Group
                • Votes:
                  0 Vote for this issue
                  Watchers:
                  6 Start watching this issue

                  Dates

                  • Created:
                    Updated:
                    Resolved: