eclipse-ee4j / glassfish

Eclipse GlassFish
https://eclipse-ee4j.github.io/glassfish/
369 stars 137 forks source link

Enhancement: Allow to specify protocol for URLs the server sends to the client #24918

Open OndroMih opened 2 months ago

OndroMih commented 2 months ago

Environment Details


Background (motivation)

URLs generated by GlassFish take into consideration the value of the Server Name configuration value in config -> Network Config -> Protocols -> (listener) -> HTTP. When Server Name is set, its value (including port number if specified) will be used instead of localhost in generated URLs. The generated URLs now always retain the protocol (HTTP or HTTPS) used by the listener.

In case when GlassFish is behind a proxy server, where the proxy server communicates with the outside world via HTTPS, and GlassFish communicates with the proxy via plain HTTP inside an internal network, GlassFish should generate URLs to respect how outside world communicates with the proxy, including using HTTPS in the URL. This doesn't happen now, it's only possible to create URLs with a custom domain and port, but not with a custom protocol. The URLs always start with http:// and there's no way to turn them into https:// in GlassFish.

An example:

Enhancement Description

Add a configuration option for the HTTP protocol, e.g. Server Protocol (to be in line with Server Name), which allows to change the protocol used in the generated URLs. So that if HTTPS is specified, the URL will use the https:// protocol.

Alternatively, allow using the protocol in the Server Name value, so that it could be https://mydomain.com:443". Currently, the protocol is stripped from the value of "Server Name" and the value is changed to justmydomain.com:443`.

Steps to reproduce

  1. Deploy a simple application, e.g. with a html page. Set context root to /myapp.
  2. Configure Server Name for the http-listener-1 to mydomain.com:443
  3. Open http://localhost:8080/myapp in a browser (8080 is the port of the http-listener-1)
  4. The browser will redirect to http://mydomain.com:443/myapp/ (which will end with "The connection was reset" which is expected)

image

With the enhancement and proper configuration, in point 4, the browser would redirect to https://mydomain.com/myapp/

Impact of Issue

Simpler and safer configuration of a proxy server as a load balancer for a GlassFish cluster.

Type: Enhancement Component: Network Priority: Normal