JDK-8177439 : HttpUrlConnection sends illegal "Accept" header field
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 8,9
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2017-03-17
  • Updated: 2017-03-23
  • Resolved: 2017-03-23
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)
[

ADDITIONAL OS VERSION INFORMATION :
Linux artemis 4.9.13-101.fc24.x86_64 #1 SMP Tue Mar 7 23:48:32 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
A plain HttpUrlConnection created like this:

		URL url = new URL("http", "localhost",	8888, "/");
		URLConnection conn = url.openConnection();
		conn.getInputStream();

Sends a request with a header line:

    Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2

In this list of media ranges, the media range "*; q=.2" is illegal. RFC 7231, section 5.3.2 defines a media range as 

media-range    = ( "*/*"
                      / ( type "/" "*" )
                      / ( type "/" subtype )
                      ) *( OWS ";" OWS parameter )

So the part without the parameter must be

                      ( "*/*"
                      / ( type "/" "*" )
                      / ( type "/" subtype )

This obviously does not include "*".

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the program above, use e.g. wireshark to get the header sent.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
An RFC compliant header.
ACTUAL -
See above.

REPRODUCIBILITY :
This bug can be reproduced always.

CUSTOMER SUBMITTED WORKAROUND :
Explicitly set the accept range, e.g.:

		URLConnection conn = url.openConnection();
		// URLConnection default accept header is illegal
		conn.setRequestProperty("Accept", "*/*");



Comments
This is a duplicate of JDK-8163921.
23-03-2017

To reproduce the issue , run the attached test case. Following are the results : JDK 8u121 - Fail JDK 9-ea + 161 - Fail Following is the output with JDK 9-ea : FINE: sun.net.www.MessageHeader@3b0143d35 pairs: {GET / HTTP/1.1: null}{User-Agent: Java/9-ea}{Host: localhost:8080}{Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2}{Connection: keep-alive}
23-03-2017