Add content length and date headers to CORS response

This commit is contained in:
Chris Mowforth 2014-03-06 19:43:18 +00:00 committed by Norman Maurer
parent d89bfc593e
commit 01daefe925

View File

@ -30,6 +30,8 @@ import io.netty.handler.codec.http.HttpResponse;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import java.util.Date;
/**
* Handles <a href="http://www.w3.org/TR/cors/">Cross Origin Resource Sharing</a> (CORS) requests.
* <p>
@ -62,6 +64,8 @@ public class CorsHandler extends ChannelDuplexHandler {
private void handlePreflight(final ChannelHandlerContext ctx, final HttpRequest request) {
final HttpResponse response = new DefaultHttpResponse(request.getProtocolVersion(), OK);
if (setOrigin(response)) {
HttpHeaders.setContentLength(response, 0);
HttpHeaders.setDate(response, new Date());
setAllowMethods(response);
setAllowHeaders(response);
setAllowCredentials(response);