Skip to content

Commit

Permalink
pool: add CORS support for HTTP requests
Browse files Browse the repository at this point in the history
Motivation:

Download and upload via HTTPS in dCacheView requires the pool to support
CORS.

Modification:

Add Netty built-in support for CORS.

Result:

dCacheView upload and download now succeeds.

Target: master
Request: 4.2
Requires-notes: yes
Requires-book: no
Patch: https://rb.dcache.org/r/11357/
Acked-by: Tigran Mkrtchyan
  • Loading branch information
paulmillar committed Nov 14, 2018
1 parent 7f81b8e commit 049c87a
Showing 1 changed file with 14 additions and 0 deletions.
Expand Up @@ -22,6 +22,9 @@
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.http.HttpRequestDecoder;
import io.netty.handler.codec.http.HttpResponseEncoder;
import io.netty.handler.codec.http.cors.CorsConfig;
import io.netty.handler.codec.http.cors.CorsConfigBuilder;
import io.netty.handler.codec.http.cors.CorsHandler;
import io.netty.handler.logging.LoggingHandler;
import io.netty.handler.stream.ChunkedWriteHandler;
import io.netty.handler.timeout.IdleStateHandler;
Expand All @@ -46,6 +49,9 @@
import org.dcache.pool.movers.NettyTransferService;
import org.dcache.util.NetworkUtils;

import static io.netty.handler.codec.http.HttpHeaderNames.*;
import static io.netty.handler.codec.http.HttpMethod.*;

/**
* Netty-based HTTP transfer service.
*
Expand Down Expand Up @@ -168,6 +174,14 @@ protected void addChannelHandlers(ChannelPipeline pipeline)
pipeline.addLast("custom-headers", new CustomResponseHeadersHandler(customHeaders));
}

CorsConfig corsConfig = CorsConfigBuilder.forAnyOrigin()
.allowNullOrigin()
.allowedRequestMethods(GET, PUT, HEAD)
.allowedRequestHeaders(CONTENT_TYPE, AUTHORIZATION, CONTENT_MD5,
"Want-Digest", "suppress-www-authenticate")
.build();
pipeline.addLast("cors", new CorsHandler(corsConfig));

pipeline.addLast("transfer", new HttpPoolRequestHandler(this, chunkSize));
}
}

0 comments on commit 049c87a

Please sign in to comment.