fix(http-server): Additional null check to fix an issue in native-image
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Johannes Frohnmeyer 2024-04-21 00:26:25 +02:00
parent 12aec5bfda
commit c455aa42a8
Signed by: Johannes
GPG Key ID: E76429612C2929F4
1 changed files with 7 additions and 3 deletions

View File

@ -112,6 +112,8 @@ import java.util.zip.GZIPOutputStream;
* @since 2008-07-24
*/
public class JLHTTPServer {
private static final System.Logger LOGGER = System.getLogger("commons-http-server");
/**
* The SimpleDateFormat-compatible formats of dates which must be supported.
* Note that all generated date fields must be in the RFC 1123 format only,
@ -443,9 +445,10 @@ public class JLHTTPServer {
* or the default virtual host
*/
public VirtualHost getVirtualHost() {
return host != null ? host
: (host = JLHTTPServer.this.getVirtualHost(getBaseURL().getHost())) != null ? host
: (host = JLHTTPServer.this.getVirtualHost(null));
if (host != null) return host;
URL baseUrl = getBaseURL();
if (baseUrl != null && (host = JLHTTPServer.this.getVirtualHost(baseUrl.getHost())) != null) return host;
return host = JLHTTPServer.this.getVirtualHost(null);
}
/**
@ -981,6 +984,7 @@ public class JLHTTPServer {
resp = new Response(out); // ignore whatever headers may have already been set
resp.getHeaders().add("Connection", "close"); // about to close connection
resp.sendError(500, "Error processing request: " + t.getMessage());
LOGGER.log(System.Logger.Level.WARNING, "Error processing request", t);
} // otherwise just abort the connection since we can't recover
break; // proceed to close connection
} finally {