use of oap.http.cors.RequestCors in project oap by oaplatform.
the class BlockingHandlerAdapter method handle.
@Override
public void handle(final HttpRequest httpRequest, final HttpResponse httpResponse, final HttpContext httpContext) throws IOException {
log.trace("Handling [{}]", httpRequest);
final HttpInetConnection connection = (HttpInetConnection) httpContext.getAttribute(HTTP_CONNECTION);
final InetAddress remoteAddress = connection.getRemoteAddress();
final String httpContextProtocol = String.valueOf(httpContext.getAttribute("protocol"));
final Request request = new Request(httpRequest, new Context(location, remoteAddress, httpContextProtocol));
RequestCors cors = corsPolicy.getCors(request);
final Response response = new Response(httpResponse, cors);
if (Protocol.LOCAL.equals(this.protocol) && !Inet.isLocalAddress(remoteAddress)) {
response.respond(HTTP_FORBIDDEN);
} else if (cors.autoOptions && request.httpMethod == Request.HttpMethod.OPTIONS) {
response.respond(NO_CONTENT);
} else {
handler.handle(request, response);
}
}
Aggregations