Skip to content

pass Headers as part of prepare_request #872

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

Merged
merged 3 commits into from
Jun 29, 2022

Conversation

bmc-msft
Copy link
Contributor

prepare_request adds the authentication related headers. When using Access Key methods, both Blob Storage and Data Tables uses data from the headers as part of canonicalized data that gets signed, which is checked at the server side.

As such, the headers must be part of what is sent to prepare_request.

See #871 for a walk through for Data Tables.

prepare_request adds the authentication related headers.  When using
Access Key methods, both Blob Storage and Data Tables uses data from the
headers as part of canonicalizized data that gets signed, which is
checked at the server sidej.

As such, the headers must be part of what is sent to prepare_request.

See Azure#871 for a walk through for Data Tables.
@bmc-msft bmc-msft linked an issue Jun 28, 2022 that may be closed by this pull request
@bmc-msft
Copy link
Contributor Author

Note: With this PR, the table_00 example from azure_data_tables now works.

@@ -178,13 +193,14 @@ impl HeaderName {

impl From<&'static str> for HeaderName {
fn from(s: &'static str) -> Self {
assert_eq!(s.to_lowercase(), s, "header names must be lower-case");
Copy link
Contributor Author

@bmc-msft bmc-msft Jun 28, 2022

Choose a reason for hiding this comment

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

This forces a canonicalization of header names to prevent issues such as what I found in data tables, where even after adding headers to the prepare_request, I found that data_tables was using Content-Type rather than content-type, which did not show up in Headers.get("content-type").

By forcing a canonicalized form here, we prevent footguns later.

Copy link
Contributor

@rylev rylev left a comment

Choose a reason for hiding this comment

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

Looks good, but I'd like to address a few small things first.

Comment on lines 158 to 162
impl Default for Headers {
fn default() -> Self {
Self::new()
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't seem like we really need this. Can we remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not really needed. I added because of a default clippy check. Instead of disabling the lint or writing our own Default, I added it to the derive.

https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default

@@ -178,13 +193,14 @@ impl HeaderName {

impl From<&'static str> for HeaderName {
fn from(s: &'static str) -> Self {
assert_eq!(s.to_lowercase(), s, "header names must be lower-case");
Copy link
Contributor

Choose a reason for hiding this comment

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

This probably should be inside HeaderName::from_static or even better in a private constructor that takes a Cow<'static, str> and constructs the HeaderName which everything uses instead of constructing the HeaderName directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

While I'd prefer this to live in from_static, I did not want to break the const attribute, which @cataggar was invested in adding, none of the methods I can come up with are const. (for loops, chars iterator, and to_lowercase)

I added a private from_cow method which is used by the From impls that does this.

@@ -44,13 +37,15 @@ impl AcquireLeaseBuilder {
url.query_pairs_mut().append_pair("comp", "lease");
self.timeout.append_to_url_query(&mut url);

let mut headers = Headers::new();
headers.insert(LEASE_ACTION, "acquire");
Copy link
Contributor

Choose a reason for hiding this comment

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

It would be nice if we could get headers.add(azure_core::LeaseAction::Acquire) to work, but we can leave that for a future PR.

@@ -47,17 +47,18 @@ impl ClearPageBuilder {
self.timeout.append_to_url_query(&mut url);
url.query_pairs_mut().append_pair("comp", "page");

let mut headers = Headers::new();
headers.insert(PAGE_WRITE, "clear");
headers.insert(BLOB_TYPE, "PageBlob");
Copy link
Contributor

Choose a reason for hiding this comment

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

Same here: it would be nice if headers.add(BlobType::PageBlob) worked.

@bmc-msft bmc-msft requested a review from rylev June 29, 2022 13:25
@rylev rylev merged commit bb940a9 into Azure:main Jun 29, 2022
@bmc-msft bmc-msft deleted the pass-headers-into-prepare-request branch June 29, 2022 14:47
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.

Azure Data Tables SharedKey does not work
3 participants