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

HTTP PUT Multi-part request headers issue #740

Closed
camilovelezr opened this issue Aug 7, 2021 · 1 comment
Closed

HTTP PUT Multi-part request headers issue #740

camilovelezr opened this issue Aug 7, 2021 · 1 comment

Comments

@camilovelezr
Copy link

Julia 1.6.1
HTTP.jl 0.9.13
MbedTLS.jl 1.0.3


Hello, I have found what I think is a bug in HTTP.put() when making a multi-part request.
POST multi-part requests work fine, I will provide an example to illustrate my point.

I am using HTTP.jl to interact with the REST API of Cordra. REST API Documentation. But I think this is a general issue.

POST Request

My code

port = "http://localhost:8000"
open("hw.txt") do io
    headers = []
    data = [
        "content" => JSON.json(Dict("This is a" => "test")),
        "File1" =>  HTTP.Multipart("MyFile", io)
    ]
    body = HTTP.Form(data)
    HTTP.post(port, headers, body; require_ssl_verification = false, status_exception = false)
end

Request

post

Notice how the content-type is automatically defined.

PUT Request

My code

port = "http://localhost:8000"
open("hw.txt") do io
    headers = []
    data = [
        "content" => JSON.json(Dict("This is a" => "test")),
        "File1" =>  HTTP.Multipart("MyFile", io)
    ]
    body = HTTP.Form(data)
    HTTP.put(port, headers, body; require_ssl_verification = false, status_exception = false)
end

Request

put

Notice how content-type is missing.
In this specific case, if I try to pass this request to Cordra, Cordra will be unable to parse the content of the request. My guess is that the issue is the missing content-type (and therefore, the missing "boundary" argument) in the headers.

Manual Fix

This problem can be fixed by manually specifying the content-type header (including manually choosing a boundary):

port = "http://localhost:8000"
open("hw.txt") do io
    headers = ["Content-type" => "multipart/form-data; boundary=myboundary"]
    data = [
        "content" => JSON.json(Dict("This is a" => "test")),
        "File1" =>  HTTP.Multipart("MyFile", io)
    ]
    body = HTTP.Form(data; boundary = "myboundary")
    HTTP.put(port, headers, body; require_ssl_verification = false, status_exception = false)
end

Request

myboundary

This request looks similar to the POST request. Cordra will accept it.


I think HTTP.put() needs some tuning to be able to generate the content-type headers when working with HTTP.Form multi-part requests.

Please let me know if any additional information is needed.
Thank you!

@fredrikekre
Copy link
Member

See https://discourse.julialang.org/t/send-multipart-request-from-julia-using-http-jl/60148/9. Wan't to make a PR to enable this for PUT too?

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

No branches or pull requests

2 participants