Skip to content
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

8278158: jwebserver should set request timeout #6737

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -28,11 +28,6 @@

/**
* Programmatic entry point to start the jwebserver tool.
*
* <p><b> This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interface are subject to change or deletion
* without notice.</b>
*/
public class JWebServer {

@@ -51,16 +46,32 @@ public class JWebServer {
* or an I/O error occurs, the server is not started and this method invokes
* System::exit with an appropriate exit code.
*
* <p> If the system property "sun.net.httpserver.maxReqTime" has not been
* set by the user, it is set to a value of 5 seconds. This is to prevent
* the server from hanging indefinitely, for example in the case of an HTTPS
* request.
*
* @param args the command-line options
* @throws NullPointerException if {@code args} is {@code null}, or if there
* are any {@code null} values in the {@code args} array
*/
public static void main(String... args) {
setMaxReqTime();

int ec = SimpleFileServerImpl.start(new PrintWriter(System.out, true, UTF_8), "jwebserver", args);
if (ec != 0) {
System.exit(ec);
} // otherwise, the server has either been started successfully and
// runs in another non-daemon thread, or -h or -version have been
// passed and the main thread has exited normally.
}

public static final String MAXREQTIME_KEY = "sun.net.httpserver.maxReqTime";
public static final String MAXREQTIME_VAL = "5";

private static void setMaxReqTime() {
if (System.getProperty(MAXREQTIME_KEY) == null) {
System.setProperty(MAXREQTIME_KEY, MAXREQTIME_VAL);
}
}
}
@@ -28,11 +28,6 @@

/**
* Programmatic entry point to start "java -m jdk.httpserver".
*
* <p><b> This is NOT part of any supported API.
* If you write code that depends on this, you do so at your own risk.
* This code and its internal interface are subject to change or deletion
* without notice.</b>
*/
public class Main {

@@ -51,16 +46,32 @@ public class Main {
* or an I/O error occurs, the server is not started and this method invokes
* System::exit with an appropriate exit code.
*
* <p> If the system property "sun.net.httpserver.maxReqTime" has not been
* set by the user, it is set to a value of 5 seconds. This is to prevent
* the server from hanging indefinitely, for example in the case of an HTTPS
* request.
*
* @param args the command-line options
* @throws NullPointerException if {@code args} is {@code null}, or if there
* are any {@code null} values in the {@code args} array
*/
public static void main(String... args) {
setMaxReqTime();

int ec = SimpleFileServerImpl.start(new PrintWriter(System.out, true, UTF_8), "java", args);
if (ec != 0) {
System.exit(ec);
} // otherwise, the server has either been started successfully and
// runs in another non-daemon thread, or -h or -version have been
// passed and the main thread has exited normally.
}

public static final String MAXREQTIME_KEY = "sun.net.httpserver.maxReqTime";
public static final String MAXREQTIME_VAL = "5";

private static void setMaxReqTime() {
if (System.getProperty(MAXREQTIME_KEY) == null) {
System.setProperty(MAXREQTIME_KEY, MAXREQTIME_VAL);
}
}
}