Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
5 changes: 5 additions & 0 deletions source/common/upstream/cds_subscription.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ void CdsSubscription::createRequest(Http::Message& request) {
request.headers().insertMethod().value().setReference(Http::Headers::get().MethodValues.Get);
request.headers().insertPath().value(
fmt::format("/v1/clusters/{}/{}", local_info_.clusterName(), local_info_.nodeName()));
request.headers().insertContentType().value().setReference(
Http::Headers::get().ContentTypeValues.Json);

const size_t empty_body_size = 0;

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.

nit: I don't think the local var here adds much. 0 is pretty obvious and I would just pass to value. Same elsewhere.

request.headers().insertContentLength().value(empty_body_size);
}

void CdsSubscription::parseResponse(const Http::Message& response) {
Expand Down
5 changes: 5 additions & 0 deletions source/common/upstream/sds_subscription.cc
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ void SdsSubscription::createRequest(Http::Message& message) {

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

const size_t empty_body_size = 0;
message.headers().insertContentLength().value(empty_body_size);
}

void SdsSubscription::onFetchComplete() {
Expand Down
5 changes: 5 additions & 0 deletions source/server/lds_subscription.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ void LdsSubscription::createRequest(Http::Message& request) {
request.headers().insertMethod().value().setReference(Http::Headers::get().MethodValues.Get);
request.headers().insertPath().value(
fmt::format("/v1/listeners/{}/{}", local_info_.clusterName(), local_info_.nodeName()));
request.headers().insertContentType().value().setReference(
Http::Headers::get().ContentTypeValues.Json);

const size_t empty_body_size = 0;
request.headers().insertContentLength().value(empty_body_size);
}

void LdsSubscription::parseResponse(const Http::Message& response) {
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
5 changes: 4 additions & 1 deletion test/common/upstream/cds_api_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ class CdsApiImplTest : public testing::Test {
{":method", v2_rest_ ? "POST" : "GET"},
{":path", v2_rest_ ? "/v2/discovery:clusters"
: "/v1/clusters/cluster_name/node_name"},
{":authority", "foo_cluster"}}),
{":authority", "foo_cluster"},
{"content-type", "application/json"},
{"content-length",
v2_rest_ ? fmt::FormatInt(request->body()->length()).str() : "0"}}),

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.

Do we need to pivot on v2 here? Can we just pivot on the existence of a body or not? Same below.

request->headers());
callbacks_ = &callbacks;
return &request_;
Expand Down
5 changes: 4 additions & 1 deletion test/server/lds_api_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ class LdsApiTest : public testing::Test {
{":method", v2_rest_ ? "POST" : "GET"},
{":path", v2_rest_ ? "/v2/discovery:listeners"
: "/v1/listeners/cluster_name/node_name"},
{":authority", "foo_cluster"}}),
{":authority", "foo_cluster"},
{"content-type", "application/json"},
{"content-length",
v2_rest_ ? fmt::FormatInt(request->body()->length()).str() : "0"}}),
request->headers());
callbacks_ = &callbacks;
return &request_;
Expand Down