curl / Mailing Lists / curl-users / Single Mail

curl-users

"HTTP error before end of send, stop sending" when redirecting to GET after POST

From: Matt McClure <matthew_at_matthewlmcclure.com>
Date: Sun, 24 Feb 2019 12:35:51 -0500

Hi,

I'm getting "HTTP error before end of send, stop sending" from curl
when I upload a file to a server that redirects to GET after POST.

It seems to me that curl should be detecting that it has finished
uploading the file instead of indicating that the response was
received "before end of send".

    [matt_at_Matthews-MBP:~/code/curl]
    Git: master
    $ curl http://localhost:8080/upload -F
"file=@/Users/matt/Downloads/test.txt" -H "Content-Type:
multipart/form-data" --trace-ascii -
    == Info: Trying ::1...
    == Info: TCP_NODELAY set
    == Info: Connected to localhost (::1) port 8080 (#0)
    => Send header, 214 bytes (0xd6)
    0000: POST /upload HTTP/1.1
    0017: Host: localhost:8080
    002d: User-Agent: curl/7.54.0
    0046: Accept: */*
    0053: Content-Length: 191
    0068: Expect: 100-continue
    007e: Content-Type: multipart/form-data; boundary=--------------------
    00be: ----05a58657f155dbf9
    00d4:
    <= Recv header, 23 bytes (0x17)
    0000: HTTP/1.1 100 Continue
    => Send data, 138 bytes (0x8a)
    0000: --------------------------05a58657f155dbf9
    002c: Content-Disposition: form-data; name="file"; filename="test.txt"
    006e: Content-Type: text/plain
    0088:
    => Send data, 5 bytes (0x5)
    0000: test.
    => Send data, 48 bytes (0x30)
    0000:
    0002: --------------------------05a58657f155dbf9--
    <= Recv header, 20 bytes (0x14)
    0000: HTTP/1.1 302 Found
    <= Recv header, 40 bytes (0x28)
    0000: Location: http://localhost:8080/upload
    <= Recv header, 37 bytes (0x25)
    0000: Date: Sun, 24 Feb 2019 17:09:21 GMT
    <= Recv header, 19 bytes (0x13)
    0000: Content-Length: 0
    == Info: HTTP error before end of send, stop sending
    <= Recv header, 2 bytes (0x2)
    0000:
    == Info: Closing connection 0

If I change the server to respond with a 200 OK status, the "HTTP
error before end of send" message no longer appears.

    [matt_at_Matthews-MBP:~/code/curl]
    Git: master
    $ curl http://localhost:8080/upload -F
"file=@/Users/matt/Downloads/test.txt" -H "Content-Type:
multipart/form-data" --trace-ascii -
    == Info: Trying ::1...
    == Info: TCP_NODELAY set
    == Info: Connected to localhost (::1) port 8080 (#0)
    => Send header, 214 bytes (0xd6)
    0000: POST /upload HTTP/1.1
    0017: Host: localhost:8080
    002d: User-Agent: curl/7.54.0
    0046: Accept: */*
    0053: Content-Length: 191
    0068: Expect: 100-continue
    007e: Content-Type: multipart/form-data; boundary=--------------------
    00be: ----97b6225990ffffa9
    00d4:
    <= Recv header, 23 bytes (0x17)
    0000: HTTP/1.1 100 Continue
    => Send data, 138 bytes (0x8a)
    0000: --------------------------97b6225990ffffa9
    002c: Content-Disposition: form-data; name="file"; filename="test.txt"
    006e: Content-Type: text/plain
    0088:
    => Send data, 5 bytes (0x5)
    0000: test.
    => Send data, 48 bytes (0x30)
    0000:
    0002: --------------------------97b6225990ffffa9--
    <= Recv header, 17 bytes (0x11)
    0000: HTTP/1.1 200 OK
    <= Recv header, 41 bytes (0x29)
    0000: Content-Type: text/plain; charset=utf-8
    <= Recv header, 37 bytes (0x25)
    0000: Date: Sun, 24 Feb 2019 17:07:46 GMT
    <= Recv header, 20 bytes (0x14)
    0000: Content-Length: 20
    <= Recv header, 2 bytes (0x2)
    0000:
    <= Recv data, 20 bytes (0x14)
    0000: 'test.txt' uploaded!
    'test.txt' uploaded!== Info: Connection #0 to host localhost left intact

The server is using the sample code at
https://github.com/gin-gonic/gin/blob/master/README.md#single-file

The sample code as given uses a 200 OK status.

The error in the first case above occurs when the code:

    c.String(http.StatusOK, fmt.Sprintf("'%s' uploaded!", file.Filename))

is changed to:

    c.Redirect(http.StatusFound, "http://localhost:8080/upload")

I see that the "HTTP error before end of send" message comes from
https://github.com/curl/curl/blob/942eb09e8a97b58b6ba8df280400322d201bcbd4/lib/http.c#L3469

It looks like `k->upload_done` is false, even though after some
debugging I could see that `k->writebytecount` was 191, the full
amount.

There is some code at
https://github.com/curl/curl/blob/942eb09e8a97b58b6ba8df280400322d201bcbd4/lib/http.c#L2981
that sets `upload_done = TRUE` but it seems to test `writebytecount`
before the data is sent and seems not to execute again before the 302
Found status is handled.

Does this indicate something I'm doing wrong in the server?

A bug in curl?

A benign info message that I can safely ignore?

Something else?

Thanks!

-- 
http://matthewlmcclure.com
-----------------------------------------------------------
Unsubscribe: https://cool.haxx.se/list/listinfo/curl-users
Etiquette:   https://curl.haxx.se/mail/etiquette.html
Received on 2019-02-24