Skip to content

Commit

Permalink
Set Content-Type automatically for PUT requests with form data, fixes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
fredrikekre committed Sep 27, 2021
1 parent 3b13562 commit 9ae809e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/MessageRequest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function request(::Type{MessageLayer{Next}},
setheader(headers, "Content-Length" => "0")
end
end
if !hasheader(headers, "Content-Type") && body isa Form && method == "POST"
if !hasheader(headers, "Content-Type") && body isa Form && method in ("POST", "PUT")
# "Content-Type" => "multipart/form-data; boundary=..."
setheader(headers, content_type(body))
end
Expand Down
4 changes: 3 additions & 1 deletion test/multipart.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
headers = Dict("User-Agent" => "HTTP.jl")
body = HTTP.Form(Dict())
uri = "https://httpbin.org/post"
uri_put = "https://httpbin.org/put"
@testset "Setting of Content-Type" begin
for r in (HTTP.request("POST", uri, headers, body), HTTP.post(uri, headers, body))
for r in (HTTP.request("POST", uri, headers, body), HTTP.post(uri, headers, body),
HTTP.request("PUT", uri_put, headers, body), HTTP.put(uri_put, headers, body))
@test r.status == 200
json = JSON.parse(IOBuffer(HTTP.payload(r)))
@test startswith(json["headers"]["Content-Type"], "multipart/form-data; boundary=")
Expand Down

0 comments on commit 9ae809e

Please sign in to comment.