Search in sources :

Example 1 with ProxyResponse

use of com.facebook.presto.proxy.ProxyResponseHandler.ProxyResponse in project presto by prestodb.

the class ProxyResource method performRequest.

private void performRequest(HttpServletRequest servletRequest, AsyncResponse asyncResponse, Request.Builder requestBuilder, Function<ProxyResponse, Response> responseBuilder) {
    setupXForwardedFor(servletRequest, requestBuilder);
    setupBearerToken(servletRequest, requestBuilder);
    for (String name : list(servletRequest.getHeaderNames())) {
        if (isPrestoHeader(name) || name.equalsIgnoreCase(COOKIE)) {
            for (String value : list(servletRequest.getHeaders(name))) {
                requestBuilder.addHeader(name, value);
            }
        } else if (name.equalsIgnoreCase(USER_AGENT)) {
            for (String value : list(servletRequest.getHeaders(name))) {
                requestBuilder.addHeader(name, "[Presto Proxy] " + value);
            }
        }
    }
    Request request = requestBuilder.setPreserveAuthorizationOnRedirect(true).build();
    ListenableFuture<Response> future = executeHttp(request).transform(responseBuilder::apply, executor).catching(ProxyException.class, e -> handleProxyException(request, e), directExecutor());
    setupAsyncResponse(asyncResponse, future);
}
Also used : ProxyResponse(com.facebook.presto.proxy.ProxyResponseHandler.ProxyResponse) AsyncResponse(javax.ws.rs.container.AsyncResponse) Response(javax.ws.rs.core.Response) AsyncResponseHandler.bindAsyncResponse(com.facebook.airlift.http.server.AsyncResponseHandler.bindAsyncResponse) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(com.facebook.airlift.http.client.Request)

Aggregations

Request (com.facebook.airlift.http.client.Request)1 AsyncResponseHandler.bindAsyncResponse (com.facebook.airlift.http.server.AsyncResponseHandler.bindAsyncResponse)1 ProxyResponse (com.facebook.presto.proxy.ProxyResponseHandler.ProxyResponse)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 AsyncResponse (javax.ws.rs.container.AsyncResponse)1 Response (javax.ws.rs.core.Response)1