Java HTTPHandler not triggered on Firefox proxy CONNECT method request


Is there a way to support CONNECT HTTP Requests with the Oracle HTTPServer class?

Note: If you do not want to deal with this, Jetty seems to not have this problem with their HTTPServer class (even when not using their ProxyHTTP implementation ConnectHandler). Grizzly however seemed to have the same issue as the default Java implementation, not surprising since they were both made by Oracle.

Explanation and Difficulty:

Note: I include this to provided a detailed explanation of what I believe to be the issue.

I've recently been trying to make a HTTP proxy for secure (HTTPS) connections on Firefox. The way this is accomplished is the CONNECT method (IETF RFC 2817). An example of the CONNECT request from Firefox is the following (which occurred when requesting the Google homepage).

User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:58.0) Gecko/20100101 Firefox/58.0
Proxy-Connection: keep-alive
Connection: keep-alive

this differs from a normal GET request.

GET /index HTTP/1.1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:58.0) Gecko/20100101 Firefox/58.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Upgrade-Insecure-Requests: 1

The notable difference is the so called 'request target' (see this Mozilla article for details ). Specifically the normal GET request is a 'absolute path' whereas the CONNECT request target is the 'authority form'.

Using the demo server in this StackOverflow answer (simple Java HTTPServer implementation) we can see the way to register a HTTPHandler is server.createContext("/test", new MyHandler()), which according to the Oracle documentation MUST begin with a '/'. However because the 'authority form' doesn't contain a '/' at the start the handle is never triggered

Note: This is still somewhat speculation as Oracle's code is closed source, but it was confirmed by sending the same TCP request to the server with the same CONNECT request above, but one time with a leading '/' (so '/' instead of ''). With the leading '/' the handler was triggered.

With all this said my question is this,

Is there a way around this, while still using the included libraries in the Oracle version of Java?

Note: Other than writing an new HTTP Server from scratch, or using another library. In my testing Jetty did trigger the HTTPHandler. Grizzly did not (and, in my opinion, has some code quality issues).