Permalink
Browse files

Allow cross site requests to this server.

  • Loading branch information...
1 parent 9c76258 commit 42d608dec493c5184a9a147d0903f634a669b307 @seanhoughton committed Nov 6, 2011
Showing with 10 additions and 1 deletion.
  1. +10 −1 lib/cpp/src/transport/THttpServer.cpp
@@ -69,6 +69,10 @@ bool THttpServer::parseStatusLine(char* status) {
}
*http = '\0';
+ if (strcmp(method, "OPTIONS") == 0) {
+ flush();
+ return false;
+ }
if (strcmp(method, "POST") == 0) {
// POST method ok, looking for content.
return true;
@@ -91,12 +95,17 @@ void THttpServer::flush() {
"Content-Type: application/x-thrift" << CRLF <<
"Content-Length: " << len << CRLF <<
"Connection: Keep-Alive" << CRLF <<
+ "Access-Control-Allow-Origin: *" << CRLF <<
+ "Access-Control-Allow-Methods: POST, GET, OPTIONS" << CRLF <<
+ "Access-Control-Allow-Headers: X-PINGOTHER, Content-Type" << CRLF <<
+ "Access-Control-Max-Age: 1728000" << CRLF <<
CRLF;
string header = h.str();
// Write the header, then the data, then flush
transport_->write((const uint8_t*)header.c_str(), header.size());
- transport_->write(buf, len);
+ if(len > 0)
+ transport_->write(buf, len);
transport_->flush();
// Reset the buffer and header variables

0 comments on commit 42d608d

Please sign in to comment.