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

Allow any Associative as a header #132

Closed
wants to merge 2 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Allow Associative types as headers
omus committed Dec 4, 2017
commit 6e4aa85a5400ebd6a6d1439f69391db9d3a249b0
4 changes: 2 additions & 2 deletions src/client.jl
Original file line number Diff line number Diff line change
@@ -365,7 +365,7 @@ request(client::Client, req::Request;

# build Request
function request(client::Client, method, uri::URI;
headers::Dict=Headers(),
headers::Associative=Headers(),
body=FIFOBuffers.EMPTYBODY,
stream::Bool=false,
verbose::Bool=false,
@@ -408,7 +408,7 @@ an `IOBuffer` for in-memory data, or even an `HTTP.FIFOBuffer`. For complete con

Additional keyword arguments supported, include:

* `headers::Dict`: headers given as Dict to be sent with the request
* `headers::Associative`: headers given as Dict to be sent with the request
* `body`: a request body can be given as a `String`, `Vector{UInt8}`, `IO`, `HTTP.FIFOBuffer` or `Dict`; see example below for how to utilize `HTTP.FIFOBuffer` for "streaming" request bodies; a `Dict` argument will be converted to a multipart form upload
* `stream::Bool=false`: enable response body streaming; depending on the response body size, the request will return before the full body has been received; as the response body is read, additional bytes will be recieved and put in the response body. Readers should read until `eof(response.body) == true`; see below for an example of response streaming
* `chunksize::Int`: if a request body is larger than `chunksize`, the "chunked-transfer" http mechanism will be used and chunks will be sent no larger than `chunksize`; default = `nothing`
4 changes: 2 additions & 2 deletions src/types.jl
Original file line number Diff line number Diff line change
@@ -136,9 +136,9 @@ defaultheaders(::Type{Request}) = Headers(
"User-Agent" => "HTTP.jl/0.0.0",
"Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8,application/json; charset=utf-8"
)
makeheaders(d::Dict) = Headers((string(k), string(v)) for (k, v) in d)
makeheaders(d::Associative) = Headers((string(k), string(v)) for (k, v) in d)

function Request(m::HTTP.Method, uri::URI, userheaders::Dict, b;
function Request(m::HTTP.Method, uri::URI, userheaders::Associative, b;
options::RequestOptions=RequestOptions(),
verbose::Bool=false,
logger::Option{IO}=STDOUT)