THRIFT-2858 Enable header field case insensitive match in THttpServer
Client: cpp
Patch: Ben Craig <bencraig@apache.org>
Windows build works now
This closes #552
diff --git a/lib/cpp/src/thrift/transport/THttpServer.cpp b/lib/cpp/src/thrift/transport/THttpServer.cpp
index 705e34a..a20d612 100644
--- a/lib/cpp/src/thrift/transport/THttpServer.cpp
+++ b/lib/cpp/src/thrift/transport/THttpServer.cpp
@@ -23,6 +23,9 @@
#include <thrift/transport/THttpServer.h>
#include <thrift/transport/TSocket.h>
+#ifdef _MSC_VER
+#include <Shlwapi.h>
+#endif
namespace apache {
namespace thrift {
@@ -36,6 +39,14 @@
THttpServer::~THttpServer() {
}
+#ifdef _MSC_VER
+ #define THRIFT_strncasecmp(str1, str2, len) _strnicmp(str1, str2, len)
+ #define THRIFT_strcasestr(haystack, needle) StrStrIA(haystack, needle)
+#else
+ #define THRIFT_strncasecmp(str1, str2, len) strncasecmp(str1, str2, len)
+ #define THRIFT_strcasestr(haystack, needle) strcasestr(haystack, needle)
+#endif
+
void THttpServer::parseHeader(char* header) {
char* colon = strchr(header, ':');
if (colon == NULL) {
@@ -44,11 +55,11 @@
size_t sz = colon - header;
char* value = colon + 1;
- if (strncasecmp(header, "Transfer-Encoding", sz) == 0) {
- if (strcasestr(value, "chunked") != NULL) {
+ if (THRIFT_strncasecmp(header, "Transfer-Encoding", sz) == 0) {
+ if (THRIFT_strcasestr(value, "chunked") != NULL) {
chunked_ = true;
}
- } else if (strncasecmp(header, "Content-length", sz) == 0) {
+ } else if (THRIFT_strncasecmp(header, "Content-length", sz) == 0) {
chunked_ = false;
contentLength_ = atoi(value);
} else if (strncmp(header, "X-Forwarded-For", sz) == 0) {
diff --git a/lib/cpp/src/thrift/windows/config.h b/lib/cpp/src/thrift/windows/config.h
index dd0da35..24a94f8 100644
--- a/lib/cpp/src/thrift/windows/config.h
+++ b/lib/cpp/src/thrift/windows/config.h
@@ -94,5 +94,6 @@
#else
#pragma comment(lib, "Ws2_32.lib")
#pragma comment(lib, "advapi32.lib") // For security APIs in TPipeServer
+#pragma comment(lib, "Shlwapi.lib") // For StrStrIA in TPipeServer
#endif
#endif // _THRIFT_WINDOWS_CONFIG_H_