public final class HttpCorsServer
extends java.lang.Object
CORS is configured in HttpCorsServerInitializer and by updating the config you can
try out various combinations, like using a specific origin instead of a
wildcard origin ('*').
The file src/main/resources/cors/cors.html contains a very basic example client
which can be used to try out different configurations. For example, you can add
custom headers to force a CORS preflight request to make the request fail. Then
to enable a successful request, configure the CorsHandler to allow that/those
request headers.
src/main/resources/cors/cors.html using a web server
or load it from the file system using a web browser.
src/main/resources/cors/cors.html
using a web server. You can then add a new host name to your systems hosts file, for
example if you are on Linux you may update /etc/hosts to add an additional name
for you local system:
127.0.0.1 localhost domain1.comNow, you should be able to access
http://domain1.com/cors.html depending on how you
have configured you local web server the exact url may differ.
src/main/resources/cors/cors.html in a web browser. You should see
loaded page and in the text area the following message:
'CORS is not working'If you inspect the headers being sent using your browser you'll see that the 'Origin' request header is
'null'. This is expected and happens when you load a file from the
local file system. Netty can handle this by configuring the CorsHandler which is done
in the HttpCorsServerInitializer.| 构造器和说明 |
|---|
HttpCorsServer() |
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
main(java.lang.String[] args) |