allow to configure cors on http
Allow to configure cors on http, if its enabled or not, and what it should output
This commit is contained in:
parent
f659cad8d6
commit
b26fd600f0
|
@ -73,13 +73,15 @@ public class NettyHttpChannel implements HttpChannel {
|
|||
resp = new DefaultHttpResponse(HttpVersion.HTTP_1_1, status);
|
||||
}
|
||||
if (RestUtils.isBrowser(request.getHeader(HttpHeaders.Names.USER_AGENT))) {
|
||||
// Add support for cross-origin Ajax requests (CORS)
|
||||
resp.addHeader("Access-Control-Allow-Origin", "*");
|
||||
if (request.getMethod() == HttpMethod.OPTIONS) {
|
||||
// Allow Ajax requests based on the CORS "preflight" request
|
||||
resp.addHeader("Access-Control-Max-Age", 1728000);
|
||||
resp.addHeader("Access-Control-Allow-Methods", "OPTIONS, HEAD, GET, POST, PUT, DELETE");
|
||||
resp.addHeader("Access-Control-Allow-Headers", "X-Requested-With, Content-Type, Content-Length");
|
||||
if (transport.settings().getAsBoolean("http.cors.enabled", true)) {
|
||||
// Add support for cross-origin Ajax requests (CORS)
|
||||
resp.addHeader("Access-Control-Allow-Origin", transport.settings().get("http.cors.allow-origin", "*"));
|
||||
if (request.getMethod() == HttpMethod.OPTIONS) {
|
||||
// Allow Ajax requests based on the CORS "preflight" request
|
||||
resp.addHeader("Access-Control-Max-Age", transport.settings().getAsInt("http.cors.max-age", 1728000));
|
||||
resp.addHeader("Access-Control-Allow-Methods", transport.settings().get("http.cors.allow-methods", "OPTIONS, HEAD, GET, POST, PUT, DELETE"));
|
||||
resp.addHeader("Access-Control-Allow-Headers", transport.settings().get("http.cors.allow-headers", "X-Requested-With, Content-Type, Content-Length"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -162,6 +162,10 @@ public class NettyHttpServerTransport extends AbstractLifecycleComponent<HttpSer
|
|||
maxChunkSize, maxHeaderSize, maxInitialLineLength, this.maxContentLength, receivePredictorMin, receivePredictorMax);
|
||||
}
|
||||
|
||||
public Settings settings() {
|
||||
return this.settings;
|
||||
}
|
||||
|
||||
public void httpServerAdapter(HttpServerAdapter httpServerAdapter) {
|
||||
this.httpServerAdapter = httpServerAdapter;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue