Chromium Code Reviews| Index: native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_util.cc |
| diff --git a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_util.cc b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_util.cc |
| index c26c8983ca8b4235843e66f896f520908d3ce85d..32b32511feff91d226bcc9ffc9b0f35a5975ed99 100644 |
| --- a/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_util.cc |
| +++ b/native_client_sdk/src/tests/nacl_io_test/fake_ppapi/fake_util.cc |
| @@ -4,6 +4,10 @@ |
| #include "fake_ppapi/fake_util.h" |
| +#include <strings.h> |
| + |
| +#include <string> |
| + |
| #include <ppapi/c/pp_completion_callback.h> |
| #include <ppapi/c/pp_errors.h> |
| @@ -24,3 +28,35 @@ int32_t RunCompletionCallback(PP_CompletionCallback* callback, int32_t result) { |
| } |
| return result; |
| } |
| + |
| +bool GetHeaderValue(const std::string& headers, |
| + const std::string& key, |
| + std::string* out_value) { |
| + out_value->clear(); |
| + |
| + size_t offset = 0; |
| + while (offset != std::string::npos) { |
| + // Find the next colon; this separates the key from the value. |
| + size_t colon = headers.find(':', offset); |
| + if (colon == std::string::npos) |
| + return false; |
| + |
| + // Find the newline; this separates the value from the next header. |
| + size_t newline = headers.find('\n', offset); |
| + if (strncasecmp(key.c_str(), &headers.data()[offset], key.size()) != 0) { |
| + // Key doesn't match, skip to next header. |
| + offset = newline + 1; |
|
chanpatorikku
2016/11/14 13:54:13
Can we make this allow multiple newlines in "heade
binji
2016/11/14 22:52:31
Yes, I think this should be newline + 1.
|
| + continue; |
| + } |
| + |
| + // Key matches, extract value. First, skip leading spaces. |
| + size_t nonspace = headers.find_first_not_of(' ', colon + 1); |
| + if (nonspace == std::string::npos) |
| + return false; |
| + |
| + out_value->assign(headers, nonspace, newline - nonspace); |
| + return true; |
| + } |
| + |
| + return false; |
| +} |