-
Notifications
You must be signed in to change notification settings - Fork 175
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 ability to set a default User-Agent string to be used w/ each req… #266
Conversation
Codecov Report
@@ Coverage Diff @@
## master #266 +/- ##
========================================
Coverage ? 69.5%
========================================
Files ? 35
Lines ? 1951
Branches ? 0
========================================
Hits ? 1356
Misses ? 595
Partials ? 0
Continue to review full report at Codecov.
|
Is the user API |
@@ -1,6 +1,6 @@ | |||
module MessageRequest | |||
|
|||
export body_is_a_stream, body_was_streamed | |||
export body_is_a_stream, body_was_streamed, setuseragent! |
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.
@samoconnor, it's exported from MessageRequest, so HTTP.setuseragent!
will indeed be the user API
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.
Does thus need docs?
I feel like being a good net citizen means alnist all use HTTP
should be followed by setuseragent!(ProjectName)
@@ -37,7 +37,7 @@ end | |||
|
|||
@testset "HTTP.Servers.serve" begin | |||
|
|||
port = rand(8000:8999) | |||
port = 8086 # rand(8000:8999) |
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.
Delete commented bit?
@oxinabox, I'd say that being a good net citizen means:
|
Re curl: |
@samoconnor sounds like you've got half the doc I was suggesting written there :-) |
It was on that notion, But that is not standard practice, so it is prob not a good idea to be the first. |
I've got to say, this still seems like an anti-feature to me. We have a generic interface for sending headers with requests. It doesn't feel right to me for the HTTP Message Layer to have knowledge of the User-Agent header. The Message Layer deals with message encapsulation (Content-Length, Transfer-Encoding) and mandatory message headers (Host). It seems arbitrary to have special support for User-Agent at this layer. |
This just sounds plain more convenient than declaring a wrapper function(/s) to use everywhere in your program. Lets say someone is made a package called GoogleDrive.jl built on using Swagger.jl which is inturn (in updated to be) built on HTTP.jl So rather than wrapping Then say someone uses GoogleDrive.jl in a package, maybe they want to set the user-agent themself because reasons. Now the wrapper functions must continue upwards. This seems intensely inelegant. This is kinda different to the Node.js thread, since this particular PR does not actually set the user-agent for HTTP.jl. Just provides a method allowing users to set it. |
@oxinabox, I agree that the use case of over-riding User-Agent in a multi-library stack is one that should be supported elegantly.
That's true. But the vibe I get from the Node.js thread is that the maintainers of the library see User-Agent as an application-level thing, not a low-level HTTP stack thing. So I think it is relevant. I'd be happier if this was not done at the Message Layer and was made more generic. e.g. the interface could be The implementation could be done in the top level function request(::Type{DefaultHeadersLayer{Next}},
method::String, url::URI, headers, body; kw...) where Next
for h in default_headers
defaultbyfirst(headers, h)
end
return request(Next, method, url, headers, body; kw...)
end Another alternative would be to use this as a use-case for adding a custom layer. abstract type GoogleDriveLayer{Next <: Layer} <: Layer end
function request(::Type{GoogleDriveLayer{Next}},
url, req, body; kw...) where Next
setheader(req, "User-Agent" => "GoogleDrive.jl v0.1.1")
return request(Next, url, req, body; kw...)
end
HTTP.insertlayerafter(HTTP.MessageLayer, GoogleDriveLayer) One of my motivations for being a bit anal about what does and does not belong at a certain layer is to ensure that custom layers can be created without too much angst about "I want to be before thing X, but after thing Y, but I can't because they're done at the same layer". |
…uest. Fixes #161
cc: @oxinabox, @samoconnor