Skip to content

Instantly share code, notes, and snippets.

@nmische
Created November 12, 2011 00:22
Show Gist options
  • Save nmische/1359764 to your computer and use it in GitHub Desktop.
Save nmische/1359764 to your computer and use it in GitHub Desktop.
A HttpHandler for Flash policy files
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