Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async_client: minor refactor to response body handling #13339

Merged
merged 1 commit into from
Oct 1, 2020

Conversation

alyssawilk
Copy link
Contributor

As a follow-up to #13328, always creating a body buffer to avoid the pattern of null pointer derefs.

Risk Level: Medium
Testing: unit tests pass
Docs Changes: n/a
Release Notes: yes

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
@@ -258,8 +258,7 @@ void RawHttpClientImpl::check(RequestCallbacks& callbacks, Event::Dispatcher& di
Http::RequestMessagePtr message =
std::make_unique<Envoy::Http::RequestMessageImpl>(std::move(headers));
if (request_length > 0) {
message->body() =
std::make_unique<Buffer::OwnedImpl>(request.attributes().request().http().body());
message->body().add(request.attributes().request().http().body());
Copy link
Member

Choose a reason for hiding this comment

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

NIce! Thanks!

@mattklein123 mattklein123 self-assigned this Sep 30, 2020
Copy link
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Very nice!

@@ -44,15 +44,15 @@ void RemoteDataFetcher::onSuccess(const Http::AsyncClient::Request&,
const uint64_t status_code = Http::Utility::getResponseStatus(response->headers());
if (status_code == enumToInt(Http::Code::OK)) {
ENVOY_LOG(debug, "fetch remote data [uri = {}]: success", uri_.uri());
if (response->body()) {
if (response->body().length() > 0) {
Copy link
Member

Choose a reason for hiding this comment

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

Might be worth it to add an empty() method to Buffer at some point.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

haha yeah, I'm so used to getting reminded to use empty() over length() > 0 I started with that and was surprised when it didn't compile :-P

@alyssawilk alyssawilk merged commit 9fadf12 into envoyproxy:master Oct 1, 2020
@alyssawilk alyssawilk deleted the datadog2 branch June 10, 2021 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants