Archived Forum Post

Index of archived forum posts

Question:

how to add Transfer-Encoding header to http request

Oct 26 '16 at 21:43

The http server side of our project needs this header to be set for some reason. I tried HttpRequest.addHeader("Transfer-Encoding", "chunked"), but not works, the header was not present in the request...


Accepted Answer

The Transfer-Encoding header indicates the format of the request body that follows. It's no solution to just add the header -- because the body must be sent as the header describes. (The header tells the receiving end the transfer encoding of what follows.)

To understand the chunked transfer encoding, see this: https://en.wikipedia.org/wiki/Chunked_transfer_encoding

Chilkat REST can send HTTP requests using the chunked transfer encoding. In fact, in cases where the body of the request comes from a stream, that is the only possible choice. However, many servers cannot handle a client using the chunked transfer encoding. Case in point: Google Drive. The server-side of Google Drive requires a Content-Length header and is incapable of receiving a chunked request. Chilkat makes this exception for Google Drive internally, and will use the non-chunked (i.e. typical) HTTP request w/ a Content-Length if the size of the stream can be known (such as if it is a file stream).

Why do I mention all of this? Because it's best if the server simply accepts either. When implementing a protocol, it's best to avoid constraints -- i.e. requiring the peer to avoid certain aspects of the protocol. For example, the QuickBooks server-side cannot handle MIME continuation lines in the HTTP request. (WTF???) All of these "partial" implementations of protocols where restrictions need to be known in advance make it overly complicated to get anything working with your server. It almost entirely defeats the purpose of having a protocol in the first place.

My advice: Make the server accept both chunked and typical HTTP requests w/ Content-Length.


Answer

I just tried this:

Dim lo_HttpReq As New Chilkat_v9_5_0.ChilkatHttpRequest

lo_HttpReq.AddHeader "Transfer-Encoding", "chunked"
Debug.Print lo_HttpReq.GenerateRequestText

And the result was:

GET / HTTP/1.1
Transfer-Encoding: chunked
Host: domain

So the AddHeader method appears to be working. Can you post a code example that demonstrates the problem? Are you using the latest version of the Chilkat library?