An open API service indexing awesome lists of open source software.

https://github.com/georgeosddev/corsfilter

corsfilter sample
https://github.com/georgeosddev/corsfilter

Last synced: 2 months ago
JSON representation

corsfilter sample

Awesome Lists containing this project

README

        

# CorsHandler Sample

This is a sample implementation of cors handler for [Netty](https://github.com/netty/netty).

Source code is based on [Xitrum](https://github.com/ngocdaothanh/xitrum)'s downstream handler.

#Usage:

* Create policy

TreeSet allowOrigin = new TreeSet();
allowOrigin.add("*");
Boolean allowCredentials = true;
TreeSet exposeHeaders = new TreeSet();
exposeHeaders.add("x-HeaderA");
int maxAge = 100;
TreeSet allowMethods = new TreeSet();
allowMethods.add("GET");
allowMethods.add("POST");
TreeSet allowHeaders = new TreeSet();
allowHeaders.add("x-HeaderB");

CorsPolicy corsPolicy = new DefaultCorsPolicy(
allowOrigin,
allowCredentials,
exposeHeaders,
maxAge,
allowMethods,
allowHeaders
);


* Mapping policy with uri(regex)

Map policyMap = new HashMap();
policyMap.put("/", corsPolicy);
policyMap.put("/api[1-9]", corsPolicy2);


* Add pipline with handler

pipeline.addLast("cors", new CorsHandler(policyMap));