Consistent use of case insensitive keys for HTTP headers. Review: https://reviews.apache.org/r/38599
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/605a8b62 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/605a8b62 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/605a8b62 Branch: refs/heads/master Commit: 605a8b62796d5f9a7ae52a798ba1f7a08a71742f Parents: bf207e3 Author: Benjamin Mahler <[email protected]> Authored: Mon Sep 21 19:55:48 2015 -0700 Committer: Benjamin Mahler <[email protected]> Committed: Mon Sep 28 11:09:48 2015 -0700 ---------------------------------------------------------------------- src/scheduler/scheduler.cpp | 2 +- .../provisioner/docker/registry_client.cpp | 19 +++++++++---------- src/tests/executor_http_api_tests.cpp | 14 +++++++------- src/tests/http_api_tests.cpp | 20 ++++++++++---------- src/tests/master_maintenance_tests.cpp | 2 +- src/tests/reservation_endpoints_tests.cpp | 12 ++++++------ src/tests/teardown_tests.cpp | 10 +++++----- 7 files changed, 39 insertions(+), 40 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/605a8b62/src/scheduler/scheduler.cpp ---------------------------------------------------------------------- diff --git a/src/scheduler/scheduler.cpp b/src/scheduler/scheduler.cpp index ee146eb..56801ca 100644 --- a/src/scheduler/scheduler.cpp +++ b/src/scheduler/scheduler.cpp @@ -306,7 +306,7 @@ protected: // the scheduler driver does. const string body = serialize(contentType, call); - const hashmap<string, string> headers{{"Accept", stringify(contentType)}}; + const http::Headers headers{{"Accept", stringify(contentType)}}; Future<Response> response; http://git-wip-us.apache.org/repos/asf/mesos/blob/605a8b62/src/slave/containerizer/provisioner/docker/registry_client.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/provisioner/docker/registry_client.cpp b/src/slave/containerizer/provisioner/docker/registry_client.cpp index 0a96631..c2040b4 100644 --- a/src/slave/containerizer/provisioner/docker/registry_client.cpp +++ b/src/slave/containerizer/provisioner/docker/registry_client.cpp @@ -20,6 +20,7 @@ #include <process/defer.hpp> #include <process/dispatch.hpp> +#include <process/http.hpp> #include <process/io.hpp> #include "slave/containerizer/provisioner/docker/registry_client.hpp" @@ -81,12 +82,12 @@ private: Future<Response> doHttpGet( const URL& url, - const Option<hashmap<string, string>>& headers, + const Option<process::http::Headers>& headers, const Duration& timeout, bool resend, const Option<string>& lastResponse) const; - Try<hashmap<string, string>> getAuthenticationAttributes( + Try<process::http::Headers> getAuthenticationAttributes( const Response& httpResponse) const; Owned<TokenManager> tokenManager_; @@ -197,8 +198,7 @@ RegistryClientProcess::RegistryClientProcess( credentials_(creds) {} -Try<hashmap<string, string>> -RegistryClientProcess::getAuthenticationAttributes( +Try<process::http::Headers> RegistryClientProcess::getAuthenticationAttributes( const Response& httpResponse) const { if (httpResponse.headers.find("WWW-Authenticate") == @@ -217,7 +217,7 @@ RegistryClientProcess::getAuthenticationAttributes( const vector<string> authParams = strings::tokenize(authStringTokens[1], ","); - hashmap<string, string> authAttributes; + process::http::Headers authAttributes; auto addAttribute = [&authAttributes]( const string& param) -> Try<Nothing> { const vector<string> paramTokens = @@ -245,10 +245,9 @@ RegistryClientProcess::getAuthenticationAttributes( } -Future<Response> -RegistryClientProcess::doHttpGet( +Future<Response> RegistryClientProcess::doHttpGet( const URL& url, - const Option<hashmap<string, string>>& headers, + const Option<process::http::Headers>& headers, const Duration& timeout, bool resend, const Option<string>& lastResponseStatus) const @@ -319,7 +318,7 @@ RegistryClientProcess::doHttpGet( // Handle 401 Unauthorized. if (httpResponse.status == "401 Unauthorized") { - Try<hashmap<string, string>> authAttributes = + Try<process::http::Headers> authAttributes = getAuthenticationAttributes(httpResponse); if (authAttributes.isError()) { @@ -343,7 +342,7 @@ RegistryClientProcess::doHttpGet( .then(defer(self(), [=]( const Future<Token>& tokenResponse) { // Send request with acquired token. - hashmap<string, string> authHeaders = { + process::http::Headers authHeaders = { {"Authorization", "Bearer " + tokenResponse.get().raw} }; http://git-wip-us.apache.org/repos/asf/mesos/blob/605a8b62/src/tests/executor_http_api_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/executor_http_api_tests.cpp b/src/tests/executor_http_api_tests.cpp index c2c05f4..31938c2 100644 --- a/src/tests/executor_http_api_tests.cpp +++ b/src/tests/executor_http_api_tests.cpp @@ -139,7 +139,7 @@ TEST_F(ExecutorHttpApiTest, ValidJsonButInvalidProtobuf) JSON::Object object; object.values["string"] = "valid_json"; - hashmap<string, string> headers; + process::http::Headers headers; headers["Accept"] = APPLICATION_JSON; Future<Response> response = process::http::post( @@ -176,7 +176,7 @@ TEST_P(ExecutorHttpApiTest, MalformedContent) const string body = "MALFORMED_CONTENT"; const ContentType contentType = GetParam(); - hashmap<string, string> headers; + process::http::Headers headers; headers["Accept"] = stringify(contentType); Future<Response> response = process::http::post( @@ -211,7 +211,7 @@ TEST_P(ExecutorHttpApiTest, UnsupportedContentMediaType) Clock::settle(); ContentType contentType = GetParam(); - hashmap<string, string> headers; + process::http::Headers headers; headers["Accept"] = stringify(contentType); Call call; @@ -254,7 +254,7 @@ TEST_P(ExecutorHttpApiTest, MessageFromUnknownFramework) Clock::settle(); ContentType contentType = GetParam(); - hashmap<string, string> headers; + process::http::Headers headers; headers["Accept"] = stringify(contentType); Call call; @@ -325,7 +325,7 @@ TEST_P(ExecutorHttpApiTest, DefaultAccept) Clock::pause(); Clock::settle(); - hashmap<string, string> headers; + process::http::Headers headers; headers["Accept"] = "*/*"; // Only subscribe needs to 'Accept' JSON or protobuf. @@ -376,7 +376,7 @@ TEST_P(ExecutorHttpApiTest, NoAcceptHeader) // No 'Accept' header leads to all media types considered // acceptable. JSON will be chosen by default. - hashmap<string, string> headers; + process::http::Headers headers; // Only subscribe needs to 'Accept' JSON or protobuf. Call call; @@ -420,7 +420,7 @@ TEST_P(ExecutorHttpApiTest, NotAcceptable) // Retrieve the parameter passed as content type to this test. const ContentType contentType = GetParam(); - hashmap<string, string> headers; + process::http::Headers headers; headers["Accept"] = "foo"; // Only subscribe needs to 'Accept' JSON or protobuf. http://git-wip-us.apache.org/repos/asf/mesos/blob/605a8b62/src/tests/http_api_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/http_api_tests.cpp b/src/tests/http_api_tests.cpp index 7938bbb..df87afe 100644 --- a/src/tests/http_api_tests.cpp +++ b/src/tests/http_api_tests.cpp @@ -181,7 +181,7 @@ TEST_F(HttpApiTest, ValidJsonButInvalidProtobuf) JSON::Object object; object.values["string"] = "valid_json"; - hashmap<string, string> headers; + process::http::Headers headers; headers["Accept"] = APPLICATION_JSON; Future<Response> response = process::http::post( @@ -209,7 +209,7 @@ TEST_P(HttpApiTest, MalformedContent) const string body = "MALFORMED_CONTENT"; const string contentType = GetParam(); - hashmap<string, string> headers; + process::http::Headers headers; headers["Accept"] = contentType; Future<Response> response = process::http::post( @@ -235,7 +235,7 @@ TEST_P(HttpApiTest, UnsupportedContentMediaType) ASSERT_SOME(master); const string contentType = GetParam(); - hashmap<string, string> headers; + process::http::Headers headers; headers["Accept"] = contentType; Call call; @@ -277,7 +277,7 @@ TEST_P(HttpApiTest, Subscribe) // Retrieve the parameter passed as content type to this test. const string contentType = GetParam(); - hashmap<string, string> headers; + process::http::Headers headers; headers["Accept"] = contentType; Future<Response> response = process::http::streaming::post( @@ -347,7 +347,7 @@ TEST_P(HttpApiTest, SubscribedOnRetryWithForce) // Retrieve the parameter passed as content type to this test. const string contentType = GetParam(); - hashmap<string, string> headers; + process::http::Headers headers; headers["Accept"] = contentType; auto deserializer = @@ -472,7 +472,7 @@ TEST_P(HttpApiTest, UpdatePidToHttpScheduler) // Retrieve the parameter passed as content type to this test. const string contentType = GetParam(); - hashmap<string, string> headers; + process::http::Headers headers; headers["Accept"] = contentType; Future<Response> response = process::http::streaming::post( @@ -559,7 +559,7 @@ TEST_P(HttpApiTest, UpdatePidToHttpSchedulerWithoutForce) // Retrieve the parameter passed as content type to this test. const string contentType = GetParam(); - hashmap<string, string> headers; + process::http::Headers headers; headers["Accept"] = contentType; Future<Response> response = process::http::streaming::post( @@ -618,7 +618,7 @@ TEST_P(HttpApiTest, NotAcceptable) // Retrieve the parameter passed as content type to this test. const string contentType = GetParam(); - hashmap<string, string> headers; + process::http::Headers headers; headers["Accept"] = "foo"; // Only subscribe needs to 'Accept' json or protobuf. @@ -653,7 +653,7 @@ TEST_P(HttpApiTest, NoAcceptHeader) // No 'Accept' header leads to all media types considered // acceptable. JSON will be chosen by default. - hashmap<string, string> headers; + process::http::Headers headers; // Only subscribe needs to 'Accept' json or protobuf. Call call; @@ -683,7 +683,7 @@ TEST_P(HttpApiTest, DefaultAccept) Try<PID<Master> > master = StartMaster(flags); ASSERT_SOME(master); - hashmap<string, string> headers; + process::http::Headers headers; headers["Accept"] = "*/*"; // Only subscribe needs to 'Accept' json or protobuf. http://git-wip-us.apache.org/repos/asf/mesos/blob/605a8b62/src/tests/master_maintenance_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/master_maintenance_tests.cpp b/src/tests/master_maintenance_tests.cpp index 89ad138..e89ce3b 100644 --- a/src/tests/master_maintenance_tests.cpp +++ b/src/tests/master_maintenance_tests.cpp @@ -139,7 +139,7 @@ public: } // Default headers for all POST's to maintenance endpoints. - hashmap<string, string> headers; + process::http::Headers headers; const string maintenanceHostname = "maintenance-host"; http://git-wip-us.apache.org/repos/asf/mesos/blob/605a8b62/src/tests/reservation_endpoints_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/reservation_endpoints_tests.cpp b/src/tests/reservation_endpoints_tests.cpp index 398a2e1..d411852 100644 --- a/src/tests/reservation_endpoints_tests.cpp +++ b/src/tests/reservation_endpoints_tests.cpp @@ -103,10 +103,10 @@ public: return info; } - hashmap<string, string> createBasicAuthHeaders( + process::http::Headers createBasicAuthHeaders( const Credential& credential) const { - return hashmap<string, string>{{ + return process::http::Headers{{ "Authorization", "Basic " + base64::encode(credential.principal() + ":" + credential.secret()) @@ -698,7 +698,7 @@ TEST_F(ReservationEndpointsTest, InsufficientResources) frameworkInfo.role(), createReservationInfo(DEFAULT_CREDENTIAL.principal())); - hashmap<string, string> headers = createBasicAuthHeaders(DEFAULT_CREDENTIAL); + process::http::Headers headers = createBasicAuthHeaders(DEFAULT_CREDENTIAL); string body = createRequestBody(slaveId.get(), dynamicallyReserved); Future<Response> response = @@ -791,7 +791,7 @@ TEST_F(ReservationEndpointsTest, BadCredentials) Resources dynamicallyReserved = unreserved.flatten( "role", createReservationInfo(DEFAULT_CREDENTIAL.principal())); - hashmap<string, string> headers = createBasicAuthHeaders(credential); + process::http::Headers headers = createBasicAuthHeaders(credential); string body = createRequestBody(slaveId.get(), dynamicallyReserved); Future<Response> response = @@ -825,7 +825,7 @@ TEST_F(ReservationEndpointsTest, NoSlaveId) Resources dynamicallyReserved = unreserved.flatten( "role", createReservationInfo(DEFAULT_CREDENTIAL.principal())); - hashmap<string, string> headers = createBasicAuthHeaders(DEFAULT_CREDENTIAL); + process::http::Headers headers = createBasicAuthHeaders(DEFAULT_CREDENTIAL); string body = "resources=" + stringify(toJSONArray(dynamicallyReserved)); Future<Response> response = @@ -860,7 +860,7 @@ TEST_F(ReservationEndpointsTest, NoResources) Try<PID<Slave>> slave = StartSlave(); ASSERT_SOME(slave); - hashmap<string, string> headers = createBasicAuthHeaders(DEFAULT_CREDENTIAL); + process::http::Headers headers = createBasicAuthHeaders(DEFAULT_CREDENTIAL); string body = "slaveId=" + slaveId.get().value(); Future<Response> response = http://git-wip-us.apache.org/repos/asf/mesos/blob/605a8b62/src/tests/teardown_tests.cpp ---------------------------------------------------------------------- diff --git a/src/tests/teardown_tests.cpp b/src/tests/teardown_tests.cpp index daf748c..2eeead7 100644 --- a/src/tests/teardown_tests.cpp +++ b/src/tests/teardown_tests.cpp @@ -85,7 +85,7 @@ TEST_F(TeardownTest, TeardownEndpoint) AWAIT_READY(frameworkId); - hashmap<string, string> headers; + process::http::Headers headers; headers["Authorization"] = "Basic " + base64::encode(DEFAULT_CREDENTIAL.principal() + ":" + DEFAULT_CREDENTIAL.secret()); @@ -124,7 +124,7 @@ TEST_F(TeardownTest, TeardownEndpointBadCredentials) AWAIT_READY(frameworkId); - hashmap<string, string> headers; + process::http::Headers headers; headers["Authorization"] = "Basic " + base64::encode("badPrincipal:badSecret"); @@ -174,7 +174,7 @@ TEST_F(TeardownTest, TeardownEndpointGoodACLs) AWAIT_READY(frameworkId); - hashmap<string, string> headers; + process::http::Headers headers; headers["Authorization"] = "Basic " + base64::encode(DEFAULT_CREDENTIAL.principal() + ":" + DEFAULT_CREDENTIAL.secret()); @@ -222,7 +222,7 @@ TEST_F(TeardownTest, TeardownEndpointBadACLs) AWAIT_READY(frameworkId); - hashmap<string, string> headers; + process::http::Headers headers; headers["Authorization"] = "Basic " + base64::encode(DEFAULT_CREDENTIAL.principal() + ":" + DEFAULT_CREDENTIAL.secret()); @@ -262,7 +262,7 @@ TEST_F(TeardownTest, TeardownEndpointNoFrameworkId) ASSERT_EQ(DRIVER_RUNNING, driver.start()); AWAIT_READY(frameworkId); - hashmap<string, string> headers; + process::http::Headers headers; headers["Authorization"] = "Basic " + base64::encode("badPrincipal:badSecret"); Future<Response> response =
