Skip to content
Permalink
Browse files
8278158: jwebserver should set request timeout
Reviewed-by: dfuchs, michaelm
  • Loading branch information
FrauBoes committed Dec 8, 2021
1 parent 5dcdee4 commit 10e0318ff7289b248289a70a56adeff3c257de04
Showing 2 changed files with 32 additions and 10 deletions.
@@ -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);
}
}
}

1 comment on commit 10e0318

@openjdk-notifier
Copy link

@openjdk-notifier openjdk-notifier bot commented on 10e0318 Dec 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.