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

Fix empty body case #16364

Merged
merged 1 commit into from
Dec 14, 2022
Merged
Changes from all 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
12 changes: 5 additions & 7 deletions components/skus/browser/skus_url_loader_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include <utility>
#include <vector>

#include "base/json/json_writer.h"
#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "brave/components/skus/browser/rs/cxx/src/lib.rs.h"
Expand Down Expand Up @@ -97,14 +96,13 @@ void SkusUrlLoaderImpl::OnFetchComplete(
uint16_t response_code = api_request_result.response_code();
bool success = api_request_result.IsResponseCodeValid();

std::string safe_json;
if (api_request_result.value_body().is_none() ||
!base::JSONWriter::Write(api_request_result.value_body(), &safe_json)) {
success = false;
// Body might be empty here which is still a success.
Copy link
Contributor

@spylogsster spylogsster Dec 14, 2022

Choose a reason for hiding this comment

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

@supermassive do you mind to add a test for this case?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I actually reverted that block to original state. Not sure how to add proper tests here quickly

Copy link
Contributor

Choose a reason for hiding this comment

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

np, I will add later

std::vector<uint8_t> body_bytes;
if (!api_request_result.body().empty()) {
body_bytes.assign(api_request_result.body().begin(),
api_request_result.body().end());
}

std::vector<uint8_t> body_bytes(safe_json.begin(), safe_json.end());

std::vector<std::string> headers;
headers.reserve(api_request_result.headers().size());
for (const auto& header : api_request_result.headers()) {
Expand Down