1

I developed a server app which, among others, handles uploading of large chunks of data. When the upload request starts, before even receiving the chunk, the server app performs a few checks in order for the client to abort the operation if something goes wrong, instead of finding that there is an issue only after he sends gigabytes of data.

When playing with the server app using curl, I discovered a strange behavior.

  • curl starts the request, being ready to stream the data.
  • The server responds immediately with a HTTP 403 to signal a problem and provides a JSON response with the details of the problem.
  • curl fails with exit code 18 and the following output:

    curl: (18) transfer closed with 30 bytes remaining to read

When enabling verbose output, here's what I see:

$ curl -X PUT --limit-rate 2M http://127.0.0.1/blob -F files[]=@/tmp/tmp75hw30vc -v

*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 80 (#0)
> PUT /blob HTTP/1.1
> Host: 127.0.0.1
> User-Agent: curl/7.58.0
> Accept: */*
> Content-Length: 2439352842
> Content-Type: multipart/form-data; boundary=------------------------32c442f4cf8abe0c
> Expect: 100-continue
> 
< HTTP/1.1 100 Continue
< HTTP/1.1 403 FORBIDDEN
< Server: nginx/1.10.3
< Date: Sat, 29 Sep 2018 22:03:16 GMT
< Content-Type: application/json
< Content-Length: 30
< Connection: keep-alive
* HTTP error before end of send, stop sending
< 
* transfer closed with 30 bytes remaining to read
* stopped the pause stream!
* Closing connection 0
curl: (18) transfer closed with 30 bytes remaining to read

On server side, the code (using Flask) is the following:

def receive_blob():
    if _can_upload():
        return flask.jsonify({"error": "already-uploading"}), 403

    ...

I'm not sure I understand if the problem is related to my way to use Flask, or to curl options I'm using.

What should I do to avoid this situation, i.e. to make curl display the JSON error message returned by the server?


The question is not a duplicate of How to handle "100 continue" HTTP message? since mine explicitly asks how to make curl display the JSON error message. The linked question invites to add --fail which would lead instead to the output “curl: (22) The requested URL returned error: 403 FORBIDDEN”

Arseni Mourzenko
  • 50,338
  • 35
  • 112
  • 199
  • Possible duplicate of [How to handle "100 continue" HTTP message?](https://stackoverflow.com/questions/2964687/how-to-handle-100-continue-http-message) – Roman-Stop RU aggression in UA Sep 29 '18 at 22:35
  • @RomanKonoval: not sure if the question you linked as a duplicate helps. With `--fail`, the output is “curl: (22) The requested URL returned error: 403 FORBIDDEN” and not the JSON error message returned by the server. – Arseni Mourzenko Sep 29 '18 at 22:46
  • I agree it is not a duplicate. That question however has useful information. Beside others it describes one problem that you have, namely, sending '100 continue' in response when the check does not pass violates the spec of how 'expect: 100 continue' should be processed. – Roman-Stop RU aggression in UA Sep 29 '18 at 23:23

0 Answers0