RFR: 8245095: Implementation of JEP 408: Simple Web Server [v6]

Daniel Fuchs dfuchs at openjdk.java.net
Wed Sep 22 18:19:59 UTC 2021


On Wed, 22 Sep 2021 15:26:33 GMT, Julia Boes <jboes at openjdk.org> wrote:

>> This change implements a simple web server that can be run on the command-line with `java -m jdk.httpserver`.
>> 
>> This is facilitated by adding an entry point for the `jdk.httpserver` module, an implementation class whose main method is run when the above command is executed. This is the first such module entry point in the JDK.
>> 
>> The server is a minimal HTTP server that serves the static files of a given directory, similar to existing alternatives on other platforms and convenient for testing, development, and debugging.
>> 
>> Additionally, a small API is introduced for programmatic creation and customization.
>> 
>> Testing: tier1-3.
>
> Julia Boes has updated the pull request incrementally with two additional commits since the last revision:
> 
>  - change default bind address from anylocal to loopback
>  - address PR comments

When the -b option is not explicitly specified on the command line it would be good to print a message that says that the server is bound to the loopback by default, and print the command line that would be needed to bind to all interfaces instead (or instruct the user to call `java -m jdk.httpserver --help` to learn how to bind to all interfaces). I don't think your latest changes include that.

src/jdk.httpserver/share/classes/module-info.java line 55:

> 53:  *                                  [-o none|info|verbose] [-h to show options]
> 54:  *    Options:
> 55:  *    -b, --bind-address    - Address to bind to. Default: 127.0.0.1 (loopback).

This assumes that the machine on which the server is run has IPv4 configured. It might not be the case. It can also depend on whether -Djdk.net.preferIPv6Addresses=true is specified on the java command line. Maybe this should be: `127.0.0.1 (or ::1), (loopback).`

src/jdk.httpserver/share/classes/sun/net/httpserver/simpleserver/SimpleFileServerImpl.java line 52:

> 50:  *
> 51:  * <p> Unless specified as arguments, the default values are:<ul>
> 52:  * <li>bind address: 127.0.0.1 (loopback)</li>

maybe this should say: `127.0.01 (or ::1), (loopback)`

src/jdk.httpserver/share/classes/sun/net/httpserver/simpleserver/resources/simpleserver.properties line 32:

> 30: options=\
> 31: Options:\n\
> 32: -b, --bind-address    - Address to bind to. Default: 127.0.0.1 (loopback).\n\

This assumes that the machine on which the server is run has IPv4 configured. It might not be the case. It can also depend on whether -Djdk.net.preferIPv6Addresses=true is specified on the java command line. The actual address of the loopback (as returned by InetAddress.getLoopackeAddress()) should therefore preferably be passed as parameter to any message that talks about the loopback. It is not such an issue for the wildcard - because AFAIU there's no difference between 0.0.0.0 and ::0 at the OS level

src/jdk.httpserver/share/classes/sun/net/httpserver/simpleserver/resources/simpleserver.properties line 42:

> 40: opt.bindaddress=\
> 41: \-b, --bind-address    - Address to bind to. Default: 127.0.0.1 (loopback).\n\
> 42: \                         For 0.0.0.0 (all interfaces) use -b 0.0.0.0 or -b ::0.

is `opt.bindaddress` used somewhere? I couldn't find it.
Same for the other `opt.*` properties below.

-------------

PR: https://git.openjdk.java.net/jdk/pull/5505


More information about the core-libs-dev mailing list