Skip to content

Instantly share code, notes, and snippets.

@tong
Created May 22, 2012 09:03
Show Gist options
  • Save tong/2767731 to your computer and use it in GitHub Desktop.
Save tong/2767731 to your computer and use it in GitHub Desktop.
PHP HTTP proxy for XMPP/BOSH connections using CORS
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Credentials: true ");
header("Access-Control-Allow-Methods: OPTIONS, GET, POST");
header("Access-Control-Allow-Headers: Content-Type, Depth, User-Agent, X-File-Size, X-Requested-With, If-Modified-Since, X-File-Name, Cache-Control");
$url = "http://example.com/http-bind"; // URI of the HTTP/BOSH gate to the XMPP server
$postdata = file_get_contents('php://input');
$opts = array('http' =>
array(
'method' => 'POST',
'header' => 'Accept:text/xml',
'header' => 'Content-type:text/xml',
'header' => 'Content-Length: '.strlen( $postdata ),
'content' => $postdata
)
);
$context = stream_context_create( $opts );
$response = file_get_contents( $url, false, $context );
echo $response;
?>
@tong
Copy link
Author

tong commented May 22, 2012

Always make sure to put the CORS headers first, otherwise chrome is in trouble!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment