Skip to content

Commit

Permalink
Merge pull request #21373 from brave/http-1.0
Browse files Browse the repository at this point in the history
Update sku component to http 1.0
  • Loading branch information
rillian authored Jan 3, 2024
2 parents f3ada1c + e45a991 commit c17d74f
Show file tree
Hide file tree
Showing 151 changed files with 14,251 additions and 13,430 deletions.
21 changes: 18 additions & 3 deletions components/skus/browser/rs/cxx/src/httpclient.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ impl From<ffi::HttpResponse<'_>> for Result<http::Response<Vec<u8>>, InternalErr
fn from(resp: ffi::HttpResponse<'_>) -> Self {
match resp.result {
ffi::SkusResult::Ok => {
let mut response = http::Response::builder();
let mut response = http::Response::builder().status(resp.return_code);

response.status(resp.return_code);
for header in resp.headers {
let header = header.to_string();
// header: value
Expand All @@ -63,14 +62,30 @@ impl From<ffi::HttpResponse<'_>> for Result<http::Response<Vec<u8>>, InternalErr
))
.debug_unwrap()?;
let (key, value) = header.split_at(idx);
let key = http::HeaderName::try_from(key).map_err(|_| {
InternalError::InvalidCall(
concat!(
"must pass a valid HTTP header name,",
" i.e. ASCII charaters with no whitespace",
" or separator punctuation.",
"\nSee RFC 9110 section 5.6.2 for details.",
)
.to_string(),
)
})?;
let value = value
.get(1..)
.ok_or(InternalError::InvalidCall(
"must pass headers as `KEY: VALUE`".to_string(),
))
.debug_unwrap()?;
let value = http::HeaderValue::try_from(value).map_err(|_| {
InternalError::InvalidCall(
"must pass a valid (ASCII-printable) HTTP header value".to_string(),
)
})?;

response.header(key, value);
response.headers_mut().ok_or(InternalError::BorrowFailed)?.insert(key, value);
}

response
Expand Down
2 changes: 1 addition & 1 deletion components/skus/browser/rs/lib/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ rust_static_library("rust_lib") {
"//brave/third_party/rust/data_encoding/v2:lib",
"//brave/third_party/rust/futures_retry/v0_5:lib",
"//brave/third_party/rust/hmac/v0_10:lib",
"//brave/third_party/rust/http/v0_1:lib",
"//brave/third_party/rust/http/v1:lib",
"//brave/third_party/rust/rand/v0_7:lib",
"//brave/third_party/rust/sha2/v0_9:lib",
"//brave/third_party/rust/tracing/v0_1:lib",
Expand Down
2 changes: 1 addition & 1 deletion components/skus/browser/rs/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ path = "tests/e2e.rs"
required-features = ["e2e_test"]

[dependencies]
http = { version = "0.1" }
http = { version = "1" }
async-trait = "0.1.64"
rand = { version = "0.7" }
serde_json = "1.0"
Expand Down
4 changes: 1 addition & 3 deletions components/skus/browser/rs/lib/src/sdk/credentials/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,7 @@ where

let request_with_retries = FutureRetry::new(
|| async move {
let mut builder = http::Request::builder();
builder.method("GET");
builder.uri(format!(
let builder = http::Request::builder().method("GET").uri(format!(
"{}/v1/orders/{}/credentials/items/{}/batches/{}",
self.base_url, order_id, item_id, request_id
));
Expand Down
17 changes: 11 additions & 6 deletions components/skus/browser/rs/lib/src/sdk/orders.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
// Copyright (c) 2021 The Brave Authors. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

use core::convert::{TryFrom, TryInto};

use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -210,9 +215,9 @@ where
pub async fn fetch_order(&self, order_id: &str) -> Result<Order, SkusError> {
let request_with_retries = FutureRetry::new(
|| async {
let mut builder = http::Request::builder();
builder.method("GET");
builder.uri(format!("{}/v1/orders/{}", self.base_url, order_id));
let builder = http::Request::builder()
.method("GET")
.uri(format!("{}/v1/orders/{}", self.base_url, order_id));

let req = builder.body(vec![]).unwrap();
let resp = self.fetch(req).await?;
Expand All @@ -239,9 +244,9 @@ where
event!(Level::DEBUG, order_id = order_id, "submit_receipt called");
let request_with_retries = FutureRetry::new(
|| async {
let mut builder = http::Request::builder();
builder.method("POST");
builder.uri(format!("{}/v1/orders/{}/submit-receipt", self.base_url, order_id));
let builder = http::Request::builder()
.method("POST")
.uri(format!("{}/v1/orders/{}/submit-receipt", self.base_url, order_id));

let receipt_bytes = receipt.as_bytes().to_vec();
let req =
Expand Down
17 changes: 3 additions & 14 deletions third_party/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 5 additions & 9 deletions third_party/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ build-script-outputs = ["rules.rs"]
gn-variables-lib = "cargo_manifest_dir =\n rebase_path(\"//brave/third_party/rust/html5ever/v0_25/crate\")\nrustenv = [ \"CARGO_MANIFEST_DIR=$cargo_manifest_dir\" ]\n"

[dependencies.http]
version = "0.1"
version = "1"

[dependencies.iana-time-zone]
version = "0.1"
Expand Down Expand Up @@ -308,8 +308,8 @@ package = "bls12_381"
path = "byteorder/v1/crate"
package = "byteorder"

[patch.crates-io.bytes_v0_4]
path = "bytes/v0_4/crate"
[patch.crates-io.bytes_v1]
path = "bytes/v1/crate"
package = "bytes"

[patch.crates-io.camino_v1]
Expand Down Expand Up @@ -656,8 +656,8 @@ package = "hmac"
path = "html5ever/v0_25/crate"
package = "html5ever"

[patch.crates-io.http_v0_1]
path = "http/v0_1/crate"
[patch.crates-io.http_v1]
path = "http/v1/crate"
package = "http"

[patch.crates-io.iana-time-zone_v0_1]
Expand All @@ -676,10 +676,6 @@ package = "idna"
path = "indexmap/v1/crate"
package = "indexmap"

[patch.crates-io.iovec_v0_1]
path = "iovec/v0_1/crate"
package = "iovec"

[patch.crates-io.itertools_v0_10]
path = "itertools/v0_10/crate"
package = "itertools"
Expand Down
65 changes: 0 additions & 65 deletions third_party/rust/bytes/v0_4/BUILD.gn

This file was deleted.

5 changes: 0 additions & 5 deletions third_party/rust/bytes/v0_4/crate/.cargo_vcs_info.json

This file was deleted.

86 changes: 0 additions & 86 deletions third_party/rust/bytes/v0_4/crate/CHANGELOG.md

This file was deleted.

46 changes: 0 additions & 46 deletions third_party/rust/bytes/v0_4/crate/Cargo.toml

This file was deleted.

Loading

0 comments on commit c17d74f

Please sign in to comment.