Search in sources :

Example 1 with RequestCors

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);
    }
}
Also used : HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) RequestCors(oap.http.cors.RequestCors) HttpRequest(org.apache.http.HttpRequest) HttpInetConnection(org.apache.http.HttpInetConnection) InetAddress(java.net.InetAddress)

Aggregations

InetAddress (java.net.InetAddress)1 RequestCors (oap.http.cors.RequestCors)1 HttpInetConnection (org.apache.http.HttpInetConnection)1 HttpRequest (org.apache.http.HttpRequest)1 HttpResponse (org.apache.http.HttpResponse)1 HttpContext (org.apache.http.protocol.HttpContext)1