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

Add default user agent header #1750

Merged
merged 7 commits into from Jun 30, 2020
Merged

Add default user agent header #1750

merged 7 commits into from Jun 30, 2020

Conversation

ghost
Copy link

@ghost ghost commented Nov 17, 2019

For #1296

No tests fail that didn't already fail when I ran them locally (which isn't all that hot, I know; not sure what's going on there)

Should I try to add this behaviour to the docs as well, or it okay being implicit?

@ghost
Copy link
Author

ghost commented Nov 17, 2019

Well, that travis build clearly isn't good. Let me look into that tomorrow

@ghost ghost closed this Nov 17, 2019
@ghost
Copy link
Author

ghost commented Nov 18, 2019

Hopefully that one does it; lacking access to a non-windows machine at the moment, which is my guess for why I'm seeing tens of inconsistent failures locally.

@ghost ghost reopened this Nov 18, 2019
@codecov-io
Copy link

codecov-io commented Nov 18, 2019

Codecov Report

Merging #1750 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master     #1750   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           23        23           
  Lines         2029      2043   +14     
=========================================
+ Hits          2029      2043   +14     
Flag Coverage Δ
#unittests 99.55% <100.00%> (+<0.01%) ⬆️
Impacted Files Coverage Δ
src/urllib3/util/__init__.py 100.00% <ø> (ø)
src/urllib3/connection.py 100.00% <100.00%> (ø)
src/urllib3/util/request.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 444f044...f61b547. Read the comment docs.

Copy link
Member

@sethmlarson sethmlarson left a comment

Choose a reason for hiding this comment

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

Thanks for opening this PR! 🎉 I have a few comments before it can be merged.

src/urllib3/__init__.py Outdated Show resolved Hide resolved
src/urllib3/request.py Outdated Show resolved Hide resolved
test/with_dummyserver/test_socketlevel.py Outdated Show resolved Hide resolved
@ghost
Copy link
Author

ghost commented Nov 27, 2019

Whelp, I'll figure that one out tomorrow.

@ghost
Copy link
Author

ghost commented Nov 28, 2019

I think the mysteries of the app engine is a story for another day.
Also, I just now realized the builds only show if my request is open, and then only the most recent one, so I look like I'm talking to myself. That's okay, I guess.

@ghost ghost closed this Nov 28, 2019
@pquentin
Copy link
Member

@DonaCthulhuote We do follow your progress with attention! And are happy to help out if you're stuck.

@ghost
Copy link
Author

ghost commented Nov 28, 2019

Oh, just realized what that comment sounded like; shouldn't write things other people can see when I'm tired. I simply thought it was funny that the context for my statements was disappearing.

And not stuck (yet); just discovering that writing code for multiple python versions is a skill in and of itself.

@ghost
Copy link
Author

ghost commented Jan 1, 2020

I'm certain the tests will all pass now. Prove me wrong, travis!

@ghost ghost reopened this Jan 1, 2020
@pquentin
Copy link
Member

pquentin commented Jan 2, 2020

Just a quick note to mention that the remaining failures here are not in your code! So if you think this is ready for review, then it is ready indeed :)

@ghost
Copy link
Author

ghost commented Jan 2, 2020

Have at it, if you will.

@pquentin pquentin mentioned this pull request Jan 6, 2020
@pquentin
Copy link
Member

pquentin commented Jan 7, 2020

@DonaCthulhuote Sorry I'm going to ask one more thing first -- can you please rebase your commit on top of master? We only merge pull requests that pass CI, and the only way to do that here is to rebase.

@ghost
Copy link
Author

ghost commented Jan 9, 2020

I'm hoping those should still be green; my local for some reason decided it'd have trouble running tests after rebasing. If travis discovers something, I'll take a deeper look tonight.

@pquentin
Copy link
Member

@DonaCthulhuote we need to review this, sorry that we haven't be able to do it yet. You no longer need to rebase your commit on top of master since the tests pass and there are no conflicts!

@hodbn hodbn self-assigned this Jun 12, 2020
@hodbn
Copy link
Member

hodbn commented Jun 14, 2020

I've rebased the work @DonaCthulhuote did on top of master.
Although I think a default user agent is the correct behavior, I think we should let users a way to restore old, no user agent behavior. I've added a new constant named urllib3.util.SUPPRESS_USER_AGENT to allow this.

I still need to figure out where and how to document the new user agent choosing logic (default and suppressing).

Regarding @user234683's comment, I'm also leaning towards removing the version from the user agent. @sethmlarson @pquentin your thoughts?

@ghost
Copy link
Author

ghost commented Jun 14, 2020

I'd use None for the suppress headers, if it's being added only to be removed, but I don't have a good justification other than that it feels cleaner in my head.

Thanks for picking this up; I got run over by work last week, and hadn't had a chance to take another look at this.

@hodbn
Copy link
Member

hodbn commented Jun 14, 2020

@DonaCthulhuote You’re right, it is cleaner and it was my first attempt. I’ve reverted it because it didn’t work with urllib3.make_request.

The same problem will probably rise for higher-level APIs (i.e. requests) that will expose user agent as an optional argument.

What do you think?

@ghost
Copy link
Author

ghost commented Jun 14, 2020

I think I clearly missed that case, and that you've clearly put more thought into the problem then I have :) . I'll defer to you and the maintainers on the matter.

@pquentin
Copy link
Member

I don't have a strong opinion here. requests sends python-requests/2.23.0, but I'm happy with just urllib3 too.

@hodbn What's the problem with make_request?

@hodbn
Copy link
Member

hodbn commented Jun 15, 2020

My bad 🙃 not make_request but make_headers:

def make_headers(
keep_alive=None,
accept_encoding=None,
user_agent=None,
basic_auth=None,
proxy_basic_auth=None,
disable_cache=None,
):

Callers will not be able to suppress the default behavior. I guess there might be other callers that will have the same problem.
I'm not that happy with the constant I've introduced, do you think a sentinel object will be cleaner?

This was referenced Mar 15, 2021
Dobatymo pushed a commit to Dobatymo/urllib3 that referenced this pull request Mar 16, 2022
Co-authored-by: hodbn <hodbn@users.noreply.github.com>
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.

None yet

6 participants