You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ro...@apache.org on 2012/12/23 20:25:10 UTC

git commit: THRIFT-1657 Chrome browser sending OPTIONS method before POST in xmlHttpRequest Patch: Shantanu Choudhary

Updated Branches:
  refs/heads/master 5d06db63c -> b2f29d840


THRIFT-1657 Chrome browser sending OPTIONS method before POST in xmlHttpRequest
Patch: Shantanu Choudhary


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/b2f29d84
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/b2f29d84
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/b2f29d84

Branch: refs/heads/master
Commit: b2f29d84025d9dc2472632cc9bff6c8b5f9bc5b1
Parents: 5d06db6
Author: Roger Meier <ro...@apache.org>
Authored: Sun Dec 23 20:23:39 2012 +0100
Committer: Roger Meier <ro...@apache.org>
Committed: Sun Dec 23 20:23:39 2012 +0100

----------------------------------------------------------------------
 lib/cpp/src/thrift/transport/THttpServer.cpp |   28 +++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/b2f29d84/lib/cpp/src/thrift/transport/THttpServer.cpp
----------------------------------------------------------------------
diff --git a/lib/cpp/src/thrift/transport/THttpServer.cpp b/lib/cpp/src/thrift/transport/THttpServer.cpp
index 1b3fe7b..1135270 100644
--- a/lib/cpp/src/thrift/transport/THttpServer.cpp
+++ b/lib/cpp/src/thrift/transport/THttpServer.cpp
@@ -73,6 +73,34 @@ bool THttpServer::parseStatusLine(char* status) {
     // POST method ok, looking for content.
     return true;
   }
+  else if (strcmp(method, "OPTIONS") == 0) {
+    // preflight OPTIONS method, we don't need further content.
+    // how to graciously close connection?
+    uint8_t* buf;
+    uint32_t len;
+    writeBuffer_.getBuffer(&buf, &len);
+
+    // Construct the HTTP header
+    std::ostringstream h;
+    h <<
+      "HTTP/1.1 200 OK" << CRLF <<
+      "Date: " << getTimeRFC1123() << CRLF <<
+      "Access-Control-Allow-Origin: *" << CRLF <<
+      "Access-Control-Allow-Methods: POST, OPTIONS" << CRLF <<
+      "Access-Control-Allow-Headers: Content-Type" << 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);
+    transport_->flush();
+
+    // Reset the buffer and header variables
+    writeBuffer_.resetBuffer();
+    readHeaders_ = true;
+    return true;
+  }
   throw TTransportException(string("Bad Status (unsupported method): ") + status);
 }