-
Notifications
You must be signed in to change notification settings - Fork 645
Require a User-Agent header, take 2 #1696
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
Conversation
6286042
to
f92b898
Compare
☔ The latest upstream changes (presumably #1699) made this pull request unmergeable. Please resolve the merge conflicts. |
let (_app, anon) = TestApp::init().empty(); | ||
|
||
let mut req = anon.request_builder(Method::Get, "/api/v1/crates"); | ||
req.header("User-Agent", ""); |
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.
Is this testing when a User-Agent header exists, but is the empty string? If so, do we need a test where the header doesn't exist as well?
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.
Unfortunately, conduit-test doesn't give us a way to unset a header. We're setting the user agent to a non-empty string when the requests are first constructed so we don't have to set it for every test besides these two. We could refactor things to apply the default user agent later, so we have a place to construct a request without it here, but I've left it this way for two reasons:
- Explicitly setting
req.header("User-Agent", "")
makes it much more clear what this is actually testing - It'd be very odd if we were treating a header with no value differently than a header not being sent at all (the only case I'm aware of where there's a semantic difference is when sending an HTTP/1.1 -> HTTP/2 upgrade request, which specifies that an
HTTP2-Settings
header must be present)
With that in mind, do you still think it's worth the additional test?
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.
Nope, I don't. 👍 LGTM.
If testing without the header was easy to do, I'd like to see it. But I'm with you that it would be very odd if the framework was treating a non-existent header differently than an empty header.
I just brought it up because I've been bitten in different places (not HTTP headers) where non-existent != empty string.
We deployed this back in October, and quickly realized that old versions of Cargo (Rust 1.15 and earlier) didn't set a User-Agent header. Notably, the version of Cargo used for bootstrapping the compiler back then was this old, so we accidentally broke the build for rustc. We still see build traffic for these old versions, and we likely will never be willing to break `cargo build` for old versions of Cargo. However, as we discussed back in early November, we're fine with doing this for all other endpoints. This change will break versions of Cargo prior to Rust 1.16 for all operations that talk to crates.io, except for `cargo build`. We no longer receive any traffic for publish, yank, unyank, or owners from these old versions. (`cargo search` hits an endpoint that is also hit by bots, so I can't say for sure if it's coming from cargo or random crawlers, which is kinda the point of this requirement in the first place)
f92b898
to
44aeb47
Compare
Pulled down and tested locally. Everything seems to working when using bryan ~/projects/cratesio/ pr/1696 $ curl -i --head localhost:8888/api/v1/crates/bryan -H "User-Agent: test/1"
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Set-Cookie: cargo_session=nFPRnOh/tCaZyaOecttwdaQd8auK817pCMXxVWQ0a+o=; HttpOnly; Path=/
Content-Length: 8621
bryan ~/projects/cratesio/ pr/1696 $ curl -i --head localhost:8888/api/v1/crates/bryan -H "User-Agent:"
HTTP/1.1 403 Forbidden
Content-Length: 631
Set-Cookie: cargo_session=nFPRnOh/tCaZyaOecttwdaQd8auK817pCMXxVWQ0a+o=; HttpOnly; Path=/
bryan ~/projects/cratesio/ pr/1696 $ curl -i --head localhost:8888/api/v1/crates/bryan/0.1.0/download -H "User-Agent: test/1"
HTTP/1.1 302 Found
Location: /crates/bryan/bryan-0.1.0.crate
Set-Cookie: cargo_session=nFPRnOh/tCaZyaOecttwdaQd8auK817pCMXxVWQ0a+o=; HttpOnly; Path=/
bryan ~/projects/cratesio/ pr/1696 $ curl -i --head localhost:8888/api/v1/crates/bryan/0.1.0/download -H "User-Agent:"
HTTP/1.1 302 Found
Location: /crates/bryan/bryan-0.1.0.crate
Set-Cookie: cargo_session=nFPRnOh/tCaZyaOecttwdaQd8auK817pCMXxVWQ0a+o=; HttpOnly; Path=/ Note that this is testing the non-existence of the header. From
|
@bors r+ |
📌 Commit 44aeb47 has been approved by |
Require a User-Agent header, take 2 We deployed this back in October, and quickly realized that old versions of Cargo (Rust 1.15 and earlier) didn't set a User-Agent header. Notably, the version of Cargo used for bootstrapping the compiler back then was this old, so we accidentally broke the build for rustc. We still see build traffic for these old versions, and we likely will never be willing to break `cargo build` for old versions of Cargo. However, as we discussed back in early November, we're fine with doing this for all other endpoints. This change will break versions of Cargo prior to Rust 1.16 for all operations that talk to crates.io, except for `cargo build`. We no longer receive any traffic for publish, yank, unyank, or owners from these old versions. (`cargo search` hits an endpoint that is also hit by bots, so I can't say for sure if it's coming from cargo or random crawlers, which is kinda the point of this requirement in the first place)
☀️ Test successful - checks-travis |
It's required since rust-lang/crates.io#1696
crates.io requires it since rust-lang/crates.io#1696
crates.io requires it since rust-lang/crates.io#1696
We deployed this back in October, and quickly realized that old versions
of Cargo (Rust 1.15 and earlier) didn't set a User-Agent header.
Notably, the version of Cargo used for bootstrapping the compiler back
then was this old, so we accidentally broke the build for rustc.
We still see build traffic for these old versions, and we likely will
never be willing to break
cargo build
for old versions of Cargo.However, as we discussed back in early November, we're fine with doing
this for all other endpoints.
This change will break versions of Cargo prior to Rust 1.16 for all
operations that talk to crates.io, except for
cargo build
. We nolonger receive any traffic for publish, yank, unyank, or owners from
these old versions. (
cargo search
hits an endpoint that is also hit bybots, so I can't say for sure if it's coming from cargo or random
crawlers, which is kinda the point of this requirement in the first
place)