What is the equivelent of HttpChannel.getCurrentHttpChannel().getHttpConfiguration(); in Jetty 9.3 -
in jetty 9.2 there getcurrenthttpchannel
method on httpchannel
, use httpchannel.getcurrenthttpchannel().gethttpconfiguration();
i convert jetty 9.3 method missing , cannot find references, in docs etc, has changed. there equivalent in 9.3?
nearly of thread local access methods internals of jetty have been removed, invalid when used within http/2, websocket, , various other client contexts.
if have need access internals of jetty, have outside of servletcontext.
/* license: eclipse public license 1.0 , apache license 2.0 * see linked source file above details. */ package org.eclipse.jetty.server.handler; import java.io.ioexception; import javax.servlet.servletexception; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import org.eclipse.jetty.http.httpstatus; import org.eclipse.jetty.server.httpchannel; import org.eclipse.jetty.server.httpconfiguration; import org.eclipse.jetty.server.request; import org.eclipse.jetty.util.uriutil; /** * secured redirect handler * <p> * using information present in {@link httpconfiguration}, attempt redirect {@link httpconfiguration#getsecurescheme()} , * {@link httpconfiguration#getsecureport()} request {@link httpservletrequest#issecure()} == false. */ public class securedredirecthandler extends abstracthandler { @override public void handle(string target, request baserequest, httpservletrequest request, httpservletresponse response) throws ioexception, servletexception { httpchannel channel = baserequest.gethttpchannel(); if (baserequest.issecure() || (channel == null)) { // nothing return; } httpconfiguration httpconfig = channel.gethttpconfiguration(); if (httpconfig == null) { // no config, show error response.senderror(httpstatus.forbidden_403,"no http configuration available"); return; } if (httpconfig.getsecureport() > 0) { string scheme = httpconfig.getsecurescheme(); int port = httpconfig.getsecureport(); string url = uriutil.newuri(scheme,baserequest.getservername(),port,baserequest.getrequesturi(),baserequest.getquerystring()); response.setcontentlength(0); response.sendredirect(url); } else { response.senderror(httpstatus.forbidden_403,"not secure"); } baserequest.sethandled(true); } }
Comments
Post a Comment