This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libgcj/14012] New: HttpURLConnection.setRequestProperty() is not case insensitive


With Sun Javam the setRequestProperty() function is case insensitive.

For example on a default connection to http://apache.org/, the following request
header is sent by Sun java by default:
  GET / HTTP/1.1
  User-Agent: Java/1.4.1
  Host: apache.org
  Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
  Connection: keep-alive

And if you change the request by adding the following before getting the inpput
stream:
  conn.setRequestProperty("UsEr-AgEnT", "MyAgent/1.0");
Then the request is changed thusly:
  GET / HTTP/1.1
  UsEr-AgEnT: MyAgent/1.0
  Host: apache.org
  Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
  Connection: keep-alive

However with GCJ, the following headers are sent with the same request as above:
  GET / HTTP/1.1
  UsEr-AgEnT: MyAgent/1.0
  Content-type: application/x-www-form-urlencoded
  accept: */*
  Host: apache.org
  user-agent: gnu-libgcj/3.5.0 20040202 (experimental)
  Connection: Close

Now firstly, the lowercase format of the default headers defies convention,
anyone who is writing a client will be expecting the user-agent field to be
specified as "User-Agent".
Secondly the User-Agent field is sent twice, once in the mixed-case, and then
the default one is sent in lower case afterwards.
Thirdly, a "Content-type: application/x-www-form-urlencoded" header line is
added for no particular reason.

Further investigation reveals that the Sun engine, given the following set of
commands:
  conn.setRequestProperty("X-AgEnT", "Test 1");
  conn.setRequestProperty("x-aGeNt", "Test 2");
Ends up sending out a header line of:
  X-AgEnT: Test 2
Which has the key in the capitalization of the first line but the value is that
of the second line.

With the attached patch, GCJ will exhibit a more Sun java behaviour with respect
to setting/sending request properties.

The differences that exist between the GCJ and Sun implementations after this
patch are:
1) The "Host" line is sent before "User-Agent" line. This is consistent with the
behaviour of Mozilla (as a matter of fact, with this patch, all the standard
headers are output in Mozilla-like order)
2) The default "Accept" line has been changed to a more flexible:
    "text/xml,text/html;q=0.9,
     text/plain;q=0.8,
     video/x-mng,image/png,image/jpeg,image/gif;q=0.2,
     */*;q=0.1"

Maybe this last change is not suitable for everyone, and the Sun version of the
Accept line would be more preferred for the masses, but Sun didn't contain XML,
or PNG and that's what I'm using so that's what I put in. It's at least a
million times better than */* anyhow.

-- 
           Summary: HttpURLConnection.setRequestProperty() is not case
                    insensitive
           Product: gcc
           Version: 3.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: libgcj
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: k dot allan-gcc at au dot darkbluesea dot com
                CC: gcc-bugs at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=14012


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]