Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell the HTTP server to not send chunked encoding

I am currently writing a HTTP client to do a HTTP POST on a URL that returns a HTTP response.

However, for error messages code 400 and 500, it sends back non chunked HTTP response, and for success messages, 201, it sends a chunked response.

In the request, I am setting the content-length, so I am not sure why it is still sending us the chunked transfer encoding. Is there any other header I can set in the request, that will tell the HTTP server not to send chunked encoding?

        headerList.append("POST /v2/charges HTTP/1.1")
        headerList.append("Content-Type: application/json")
        headerList.append("host: xxxxxxxxx")
        headerList.append("request-id: ABCD001123")
        headerList.append("Content-length: %d" %len(Msg))
        hostReqHeader = "\r\n".join(headerList)
        reqData = hostReqHeader + '\r\n\r\n' + qbPosMsg

I am using sockets to send these HTTP messages, and not using httplib or requests library.

like image 270
roymustang86 Avatar asked Aug 12 '15 15:08

roymustang86


People also ask

How do I stop transfer encoding chunked?

Try adding "&headers=false" to your request. That should shorten it up and cause the response to be less likely to be chunked. Also, are you sending a HTTP/1.1 or HTTP/1.0 request? Try sending a HTTP/1.0 if your device cannot handle a HTTP/1.1 request.

What is meant by HTTP chunking?

Chunking is a technique that HTTP servers use to improve responsiveness. Chunking can help you avoid situations where the server needs to obtain dynamic content from an external source and delays sending the response to the client until receiving all of the content so the server can calculate a Content-Length header.

Why is encoding chunked?

Chunked encoding allows the sender to send additional header fields after the message body. This is important in cases where values of a field cannot be known until the content has been produced, such as when the content of the message must be digitally signed.

What encoding is the HTTP 1.1 protocol based on?

HTTP/1.1 uses content-coding values in the Accept-Encoding (section 14.3) and Content-Encoding (section 14.11) header fields. Although the value describes the content-coding, what is more important is that it indicates what decoding mechanism will be required to remove the encoding.


1 Answers

Chunked is a required feature of HTTP/1.1. If you do not require any other 1.1-specific features, specify HTTP/1.0 in your request:

    headerList.append("POST /v2/charges HTTP/1.0")
like image 81
Robᵩ Avatar answered Nov 01 '22 15:11

Robᵩ