Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions source/common/config/http_subscription_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ class HttpSubscriptionImpl : public Http::RestApiFetcher,
request.headers().insertMethod().value().setReference(Http::Headers::get().MethodValues.Post);
request.headers().insertPath().value(path_);
request.body().reset(new Buffer::OwnedImpl(MessageUtil::getJsonStringFromMessage(request_)));
request.headers().insertContentType().value().setReference(
Http::Headers::get().ContentTypeValues.Json);
request.headers().insertContentLength().value(request.body()->length());
}

void parseResponse(const Http::Message& response) override {
Expand Down
4 changes: 4 additions & 0 deletions test/common/config/http_subscription_test_harness.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class HttpSubscriptionTestHarness : public SubscriptionTestHarness {
http_callbacks_ = &callbacks;
UNREFERENCED_PARAMETER(timeout);
EXPECT_EQ("POST", std::string(request->headers().Method()->value().c_str()));
EXPECT_EQ(Http::Headers::get().ContentTypeValues.Json,
std::string(request->headers().ContentType()->value().c_str()));
EXPECT_EQ("eds_cluster", std::string(request->headers().Host()->value().c_str()));
EXPECT_EQ("/v2/discovery:endpoints",
std::string(request->headers().Path()->value().c_str()));
Expand All @@ -73,6 +75,8 @@ class HttpSubscriptionTestHarness : public SubscriptionTestHarness {
}
expected_request += "}";
EXPECT_EQ(expected_request, request->bodyAsString());
EXPECT_EQ(fmt::FormatInt(expected_request.size()).str(),
std::string(request->headers().ContentLength()->value().c_str()));
request_in_progress_ = true;
return &http_request_;
}));
Expand Down
17 changes: 11 additions & 6 deletions test/common/upstream/cds_api_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,17 @@ class CdsApiImplTest : public testing::Test {
.WillOnce(Invoke(
[&](Http::MessagePtr& request, Http::AsyncClient::Callbacks& callbacks,
const absl::optional<std::chrono::milliseconds>&) -> Http::AsyncClient::Request* {
EXPECT_EQ((Http::TestHeaderMapImpl{
{":method", v2_rest_ ? "POST" : "GET"},
{":path", v2_rest_ ? "/v2/discovery:clusters"
: "/v1/clusters/cluster_name/node_name"},
{":authority", "foo_cluster"}}),
request->headers());
Http::TestHeaderMapImpl expected_headers{
{":method", v2_rest_ ? "POST" : "GET"},

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to not just do this for v1 also?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No specific reason. My intention was only converting existing relevant tests.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's probably work doing in both places since it's more correct and it will remove the special cases from the tests?

@dio dio Aug 12, 2018

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, a clarification: If I get you correctly, you want to make v1 Envoy's SDS subscription "agent" sends requests using POST (and sends along node information to the management server) as well? Since the current SDS request only sets method (as GET) and path only.

message.headers().insertMethod().value().setReference(Http::Headers::get().MethodValues.Get);
message.headers().insertPath().value("/v1/registration/" + cluster_name_);

Or keep it GET but send the node info via headers (but this is a different story).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was just suggesting to set content-length and content-type for the v1 requests so the tests don't need special casing?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can do that since the GET request for v1 has no payload sent along with the request.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can set content-length to 0 and still set the content-type? It's not a big deal but it seems like we should be consistent if possible?

{":path",
v2_rest_ ? "/v2/discovery:clusters" : "/v1/clusters/cluster_name/node_name"},
{":authority", "foo_cluster"}};
if (v2_rest_) {
expected_headers.addCopy("content-type", "application/json");
expected_headers.addCopy("content-length",
fmt::FormatInt(request->body()->length()).str());
}
EXPECT_EQ(expected_headers, request->headers());
callbacks_ = &callbacks;
return &request_;
}));
Expand Down
17 changes: 11 additions & 6 deletions test/server/lds_api_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,17 @@ class LdsApiTest : public testing::Test {
.WillOnce(Invoke(
[&](Http::MessagePtr& request, Http::AsyncClient::Callbacks& callbacks,
const absl::optional<std::chrono::milliseconds>&) -> Http::AsyncClient::Request* {
EXPECT_EQ((Http::TestHeaderMapImpl{
{":method", v2_rest_ ? "POST" : "GET"},
{":path", v2_rest_ ? "/v2/discovery:listeners"
: "/v1/listeners/cluster_name/node_name"},
{":authority", "foo_cluster"}}),
request->headers());
Http::TestHeaderMapImpl expected_headers{
{":method", v2_rest_ ? "POST" : "GET"},
{":path",
v2_rest_ ? "/v2/discovery:listeners" : "/v1/listeners/cluster_name/node_name"},
{":authority", "foo_cluster"}};
if (v2_rest_) {
expected_headers.addCopy("content-type", "application/json");
expected_headers.addCopy("content-length",
fmt::FormatInt(request->body()->length()).str());
}
EXPECT_EQ(expected_headers, request->headers());
callbacks_ = &callbacks;
return &request_;
}));
Expand Down