use of org.eclipse.jetty.server.HttpChannel in project jetty.project by eclipse.
the class IPAccessHandler method handle.
/* ------------------------------------------------------------ */
/**
* Checks the incoming request against the whitelist and blacklist
*
* @see org.eclipse.jetty.server.handler.HandlerWrapper#handle(java.lang.String, org.eclipse.jetty.server.Request, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
// Get the real remote IP (not the one set by the forwarded headers (which may be forged))
HttpChannel channel = baseRequest.getHttpChannel();
if (channel != null) {
EndPoint endp = channel.getEndPoint();
if (endp != null) {
InetSocketAddress address = endp.getRemoteAddress();
if (address != null && !isAddrUriAllowed(address.getHostString(), baseRequest.getPathInfo())) {
response.sendError(HttpStatus.FORBIDDEN_403);
baseRequest.setHandled(true);
return;
}
}
}
getHandler().handle(target, baseRequest, request, response);
}
use of org.eclipse.jetty.server.HttpChannel in project jetty.project by eclipse.
the class SecuredRedirectHandler method handle.
@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 to do
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);
}
use of org.eclipse.jetty.server.HttpChannel in project incubator-skywalking by apache.
the class HandleInterceptor method beforeMethod.
@Override
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable {
HttpChannel httpChannel = (HttpChannel) allArguments[0];
HttpServletRequest servletRequest = httpChannel.getRequest();
ContextCarrier contextCarrier = new ContextCarrier();
CarrierItem next = contextCarrier.items();
while (next.hasNext()) {
next = next.next();
next.setHeadValue(servletRequest.getHeader(next.getHeadKey()));
}
AbstractSpan span = ContextManager.createEntrySpan(servletRequest.getRequestURI(), contextCarrier);
Tags.URL.set(span, servletRequest.getRequestURL().toString());
Tags.HTTP.METHOD.set(span, servletRequest.getMethod());
span.setComponent(ComponentsDefine.JETTY_SERVER);
SpanLayer.asHttp(span);
}
use of org.eclipse.jetty.server.HttpChannel in project incubator-skywalking by apache.
the class HandleInterceptor method afterMethod.
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
HttpChannel httpChannel = (HttpChannel) allArguments[0];
HttpServletResponse servletResponse = httpChannel.getResponse();
AbstractSpan span = ContextManager.activeSpan();
if (servletResponse.getStatus() >= 400) {
span.errorOccurred();
Tags.STATUS_CODE.set(span, Integer.toString(servletResponse.getStatus()));
}
ContextManager.stopSpan();
return ret;
}
use of org.eclipse.jetty.server.HttpChannel in project neo4j by neo4j.
the class HttpsRequestCustomizerTest method newRequest.
private static Request newRequest() {
HttpChannel channel = mock(HttpChannel.class);
Response response = new Response(channel, mock(HttpOutput.class));
Request request = new Request(channel, mock(HttpInput.class));
when(channel.getRequest()).thenReturn(request);
when(channel.getResponse()).thenReturn(response);
return request;
}
Aggregations