curl / Mailing Lists / curl-users / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

"HTTP error before end of send, stop sending" when redirecting and post data is empty

From: armand bendanan via curl-users <curl-users_at_lists.haxx.se>
Date: Thu, 28 Apr 2022 10:07:35 +0300

Hi,

I want to use POST with empty data and the server will redirect.

I'm getting this error "HTTP error before end of send, stop sending" from
curl on redirect.

It seems to me that curl should detect that it has nothing to upload
instead of indicating that the response was received "before end of send".

Here are below the different CURL commands that I used and the results.

Only the first command ignores the response body and reuses the same
connection for redirection.

The other 2 commands indicate this error then close the current connection
and open a new one to the same host on redirect.

I would expect that all 3 commands reuse the same connection on redirect.

Thanks
Armand Bendanan

1/ use custom POST with --request / without data
curl https://127.0.0.1/login -v -L -b "" --insecure -X POST
-> * Ignoring the response-body
-> connection is reused with POST

2/ use custom POST with --request / with empty data (-d "")
curl https://127.0.0.1/login -v -L -b "" --insecure -X POST -d ""
-> Note: Unnecessary use of -X or --request, POST is already inferred.
-> * HTTP error before end of send, stop sending
-> connection is closed and another attempt is done with POST

3/ force a POST by sending empty data (-d "")
curl https://127.0.0.1/login -v -L -b "" --insecure -d "" --post302
-> * HTTP error before end of send, stop sending
-> connection is closed and another attempt is done with POST

Environment:
$ curl --version
curl 7.68.0 (x86_64-pc-linux-gnu) libcurl/7.68.0 OpenSSL/1.1.1f zlib/1.2.11
brotli/1.0.7 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0)
libssh/0.9.3/openssl/zlib nghttp2/1.40.0 librtmp/2.3
Release-Date: 2020-01-08
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3
pop3s rtmp rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS brotli GSS-API HTTP2 HTTPS-proxy IDN IPv6 Kerberos
Largefile libz NTLM NTLM_WB PSL SPNEGO SSL TLS-SRP UnixSockets
$ uname -a
Linux user-Standard-PC-i440FX-PIIX-1996 5.13.0-40-generic
#45~20.04.1-Ubuntu SMP Mon Apr 4 09:38:31 UTC 2022 x86_64 x86_64 x86_64
GNU/Linux

I am using the little server below.
Need to install flask: $ sudo pip3 install flask
How to run the server: $ sudo python3 server.py

----------------------- server.py start
from flask import Flask, redirect, url_for, escape, request, make_response

app = Flask(__name__)
app.debug = True

_at_app.route('/', methods=['GET', 'POST'])
def index():
    if 'user_cookie' in request.cookies:
        return 'Logged in as %s\n' %
escape(request.cookies.get('user_cookie'))
    return 'You are NOT logged in\n'


_at_app.route("/login", methods=['GET', 'POST'])
def login():
    if request.method == 'POST':
        redirect_to_index = redirect(url_for('index'))
        response = app.make_response(redirect_to_index)
        response.set_cookie(
            "user_cookie",
            request.form['username'] if 'username' in request.form else
'nousername')
        return response
    return '''
            <form action="" method="post">
                <p><input type=text name=username>
                <p><input type=submit value=Login>
            </form>
        '''

if __name__ == '__main__':
    app.run(port=80)
----------------------- server.py end


-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-users
Etiquette:   https://curl.haxx.se/mail/etiquette.html
Received on 2022-04-28