-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
JDK-8282354 : Remove dependancy of TestHttpServer, HttpTransaction, HttpCallback from open/test/jdk/ tests #7616
Conversation
👋 Welcome back mahendrachhipa! A progress list of the required criteria for merging this PR into |
@mahendrachhipa The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
server = new TestHttpServer (new LoopbackAddresses(), 1, 10, 0); | ||
ProxyServer pserver = new ProxyServer(InetAddress.getByName("localhost"), server.getLocalPort()); | ||
server = HttpServer.create(new InetSocketAddress(loopback, 0), 10); | ||
server.createContext("/", new LoopbackAddresses()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While here, we could use the new HttpServer::create overload that creates a server with a context (applies to all tests touched.)
I also wonder if it would make sense to change the names of the classes that implement HttpHandler to "xyzHandler" for readability, and to create a separate class for the handler instead of using the test class.
try(PrintWriter pw = new PrintWriter(exchange.getResponseBody())) { | ||
pw.print("Hello ."); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know that now UTF-8 is supposed to be the default - but I'd prefer to either make it explicit, or add a comment stating that since Java 18 PrintWriter will use UTF-8 encoding by default.
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
try(PrintWriter pw = new PrintWriter(exchange.getResponseBody())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remark here
exchange.sendResponseHeaders(200, 0); | ||
} catch (IOException e) { | ||
} | ||
try(PrintWriter pw = new PrintWriter(exchange.getResponseBody())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here too
try { | ||
exchange.getResponseHeaders().set("content-length", Long.toString(B5052093.testSize)); | ||
exchange.sendResponseHeaders(200, 0); | ||
exchange.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure that this results in the same response headers than before?
If I'm not mistaken here we will send both Content-Length and Transfer-Encoding: chunked. Was that what the previous server did, and what the test wants to test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, previously also, setting the content-length Integer.MAX_VALUE)) + 2, and was not sending any content. Here wanted to test, that URLConnection.getContentLength() does not throw NumberFormatException and return -1 if content-length is long value.
In case of HttpExchange.setResponseHeader(). If responseLength is -1, then content-length value is overridden to 0, if already set explicitly. Same is the case when responseLength is > 0. Only in the case when responseLength == 0, content-length value is not overriden if already set explicitly., thats why I am using chunked encoding and not writing any data.
} | ||
if (!uncaught.isEmpty()) { | ||
throw new RuntimeException("Unhandled exception:", uncaught.get(0)); | ||
} | ||
} | ||
} | ||
|
||
class SimpleHttpTransaction implements HttpCallback | ||
class SimpleHttpTransactionHandler implements HttpHandler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the boolean failed
should at least be volatile
trans.setResponseEntityBody (responseBody, responseBody.length); | ||
trans.sendResponse(200, "OK"); | ||
trans.sendResponseHeaders(200, 0); | ||
try(PrintWriter pw = new PrintWriter(trans.getResponseBody())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remark about UTF-8 here again
|
||
void okReply (HttpExchange req) throws IOException { | ||
req.sendResponseHeaders (200, 0); | ||
try(PrintWriter pw = new PrintWriter(req.getResponseBody())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remark about UTF-8
e.printStackTrace(); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing newline at end of file?
trans.getResponseHeaders().set("Content-length", Integer.toString(responseBody.length+1)); | ||
trans.sendResponseHeaders(200, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here again we will be mixing Content-Length and chunked
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case of HttpExchange.setResponseHeader(). If responseLength is -1, then content-length value is overridden to 0, if already set explicitly. Same is the case when responseLength is > 0. Only in the case when responseLength == 0, content-length value is not overriden if already set explicitly., that's why I am using chunked encoding and writing the data less than the content length.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand why you do it - but the client will react differently if both Content-Length and chunk are specified, as opposed to when only Content-Length is specified. So I just want to make sure that we are testing the same thing than before. If we are not testing the same thing, then you might have to use a ServerSocket directly - rather than an HttpServer, to make sure we're sending back the same things than before.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now not using Transfer-Encoding Chunk.
|
||
trans.getResponseHeaders().set("Content-length", Integer.toString(responseBody.length+1)); | ||
trans.sendResponseHeaders(200, 0); | ||
try(PrintWriter pw = new PrintWriter(trans.getResponseBody())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same remark for UTF-8
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@mahendrachhipa This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 61 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@dfuch) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
/integrate |
@mahendrachhipa |
/sponsor |
Going to push as commit 95ca944.
Your commit was automatically rebased without conflicts. |
@dfuch @mahendrachhipa Pushed as commit 95ca944. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Updated following remaining tests to remove depenedies of TestHttpServer, HttpTransaction, HttpCallback
open/test/jdk/java/net/ProxySelector/LoopbackAddresses.java
open/test/jdk/java/net/ProxySelector/ProxyTest.java
open/test/jdk/java/net/URL/PerConnectionProxy.java
open/test/jdk/java/net/URLConnection/B5052093.java
open/test/jdk/sun/net/www/AuthHeaderTest.java
open/test/jdk/sun/net/www/http/KeepAliveCache/B5045306.java
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/7616/head:pull/7616
$ git checkout pull/7616
Update a local copy of the PR:
$ git checkout pull/7616
$ git pull https://git.openjdk.java.net/jdk pull/7616/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 7616
View PR using the GUI difftool:
$ git pr show -t 7616
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/7616.diff