-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Conversation
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIce! Thanks!
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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