Created
November 12, 2011 00:22
-
-
Save nmische/1359764 to your computer and use it in GitHub Desktop.
A HttpHandler for Flash policy files
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
package org.riaforge.websocketgateway; | |
import java.nio.charset.Charset; | |
import org.webbitserver.HttpControl; | |
import org.webbitserver.HttpHandler; | |
import org.webbitserver.HttpRequest; | |
import org.webbitserver.HttpResponse; | |
public class FlashPolicyFileHandler implements HttpHandler { | |
private final String body; | |
private static final Charset UTF8 = Charset.forName("UTF-8"); | |
private static final String FLASH_POLICY_REQUEST = "<policy-file-request/>\0"; | |
public FlashPolicyFileHandler(int port) { | |
this.body = "<cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"" | |
+ port | |
+ "\" /></cross-domain-policy>\0"; | |
} | |
@Override | |
public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control) { | |
if (FLASH_POLICY_REQUEST.equals(request.body())) { | |
response.content(body.getBytes(UTF8)).end(); | |
} else { | |
control.nextHandler(); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment