Skip to content

Adding files with curl via HTTP API endpoint fails unless HTTP/1.0 is used #3332

Closed

Description

@hsanjuan

Version information:

go-ipfs version: 0.4.5-dev-17c629d
Repo version: 4
System version: amd64/linux
Golang version: go1.7.1

Type: Bug

Priority: P4

Description:

Submitting a file via HTTP API /add endpoint only works forcing curl to use HTTP/1.0. Could be a Go's multipart issue, but I couldn't find anything related.

curl -v "http://localhost:5001/api/v0/add" -F file=@test/file1
*   Trying ::1...
* connect to ::1 port 5001 failed: Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 5001 (#0)
> POST /api/v0/add HTTP/1.1
> Host: localhost:5001
> User-Agent: curl/7.46.0
> Accept: */*
> Content-Length: 199
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=------------------------4f4400ca441bcea2
> 
< HTTP/1.1 200 OK
< Access-Control-Allow-Headers: X-Stream-Output, X-Chunked-Output, X-Content-Length
< Access-Control-Expose-Headers: X-Stream-Output, X-Chunked-Output, X-Content-Length
< Content-Type: application/json
< Server: go-ipfs/0.4.5-dev
< Trailer: X-Stream-Error
< Vary: Origin
< X-Chunked-Output: 1
< Date: Thu, 27 Oct 2016 14:00:16 GMT
< Connection: close
< Transfer-Encoding: chunked
< 
* Illegal or missing hexadecimal sequence in chunked-encoding
* Closing connection 0
curl: (56) Illegal or missing hexadecimal sequence in chunked-encoding

The curl message is because the daemon sends back an err: multipart: NextPart: unexpected EOF and curl is expecting a chunked-encoding (this is logged by the daemon too)

In fact, curl is expecting a 100-continue response in the first place too keep sending chunks, but that is not provided. Upload works downgrading to HTTP/1.0 though:

curl -0 -v "http://localhost:5001/api/v0/add" -F file=@test/file1
*   Trying ::1...
* connect to ::1 port 5001 failed: Connection refused
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 5001 (#0)
> POST /api/v0/add HTTP/1.0
> Host: localhost:5001
> User-Agent: curl/7.46.0
> Accept: */*
> Content-Length: 199
> Content-Type: multipart/form-data; boundary=------------------------0df218876d338326
> 
< HTTP/1.1 200 OK
< x-chunked-output: 1
< content-type: application/json; charset=utf-8
< vary: origin,accept-encoding
< cache-control: no-cache
< content-length: 73
< Date: Thu, 27 Oct 2016 14:36:25 GMT
< Connection: close
< 
{"Name":"file1","Hash":"QmdytmR4wULMd3SLo6ePF4s3WcRHWcpnJZ7bHhoj3QB13v"}
* Closing connection 0

Activity

  1. whyrusleeping commented on Oct 28, 2016

    @whyrusleeping
    Member

    Thats interesting... Lets look into this a bit more. Is this just a curl thing? or do other tools/libs work the same way?

  2. hsanjuan commented on Oct 29, 2016

    @hsanjuan
    ContributorAuthor

    So far I can say that:

    1. This endpoint works in js-ipfs with the same curl call
    2. Other endpoints with multipart-file upload seem to work well

    I have just tried curl though.

  3. Stebalien commented on Sep 5, 2017

    @Stebalien
    Member

    This appears to work now. Please reopen if it's still a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugA bug in existing code (including security flaws)status/deferredConscious decision to pause or backlogtopic/apiTopic api

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions