forked from hprose/hprose-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add addAccessControlAllowOrigin & removeAccessControlAllowOrigin for HproseHttpService.
- Loading branch information
Showing
10 changed files
with
15 additions
and
26 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ | |
* * | ||
* hprose http service class for Java. * | ||
* * | ||
* LastModified: Apr 13, 2014 * | ||
* LastModified: Apr 17, 2014 * | ||
* Author: Ma Bingyao <[email protected]> * | ||
* * | ||
\**********************************************************/ | ||
|
@@ -23,6 +23,7 @@ | |
import hprose.io.ByteBufferStream; | ||
import java.io.IOException; | ||
import java.lang.reflect.Type; | ||
import java.util.HashMap; | ||
import javax.servlet.ServletConfig; | ||
import javax.servlet.ServletContext; | ||
import javax.servlet.http.HttpServletRequest; | ||
|
@@ -33,6 +34,7 @@ public class HproseHttpService extends HproseService { | |
private boolean crossDomainEnabled = false; | ||
private boolean p3pEnabled = false; | ||
private boolean getEnabled = true; | ||
private final HashMap<String, Boolean> origins = new HashMap<String, Boolean>(); | ||
private static final ThreadLocal<HttpContext> currentContext = new ThreadLocal<HttpContext>(); | ||
|
||
public static HttpContext getCurrentContext() { | ||
|
@@ -81,6 +83,14 @@ public void setGetEnabled(boolean enabled) { | |
getEnabled = enabled; | ||
} | ||
|
||
public void addAccessControlAllowOrigin(String origin) { | ||
origins.put(origin, true); | ||
} | ||
|
||
public void removeAccessControlAllowOrigin(String origin) { | ||
origins.remove(origin); | ||
} | ||
|
||
@Override | ||
protected Object[] fixArguments(Type[] argumentTypes, Object[] arguments, int count, Object context) { | ||
HttpContext httpContext = (HttpContext)context; | ||
|
@@ -127,8 +137,10 @@ protected void sendHeader(HttpContext httpContext) throws IOException { | |
if (crossDomainEnabled) { | ||
String origin = request.getHeader("Origin"); | ||
if (origin != null && !origin.equals("null")) { | ||
response.setHeader("Access-Control-Allow-Origin", origin); | ||
response.setHeader("Access-Control-Allow-Credentials", "true"); | ||
if (origins.isEmpty() || origins.containsKey(origin)) { | ||
response.setHeader("Access-Control-Allow-Origin", origin); | ||
response.setHeader("Access-Control-Allow-Credentials", "true"); | ||
} | ||
} | ||
else { | ||
response.setHeader("Access-Control-Allow-Origin", "*"); | ||
|