Download: chunkedpostfix.zip
unit ChunkedPostFix
===================
INTRODUCTION ------------
At least in the first version of Kylix Server Developer there is a problem with medium- to large-sized POST requests over slow connections. The HTTP protocol supports a "chunked" transmission of the content. This means that the content is transmitted bit by bit (usually some hundred bytes at a time) and each time a "chunk" is transmitted that also contains a chunk header with the size of the chunk. For more information please refer the HTTP protocol.
The CGI programmer is not involved with this task as the web server will only pass the content data to the CGI program without any chunk information. However the data is usually streamed to the CGI program at the same speed it arives. On slow connections there can be some milliseconds delay or even more.
Unfortunately TWebRequest tries only once to read the content data from the web server and then continues without to check if all data could be read. Because of the reason descibed above this can be a problem.
The result is that the exception EConvertError is raised because a URL-encoded char has not been truncated or that at least some content fields are beind missed.
I noticed this problem with Kylix 1.0 server developer, don't know if it still exists in newer versions.
HOW THE FIX WORKS =================
I made a simple workaround that simply calls WebRequest.ReadString until all data (ContentLength) has been received. For security reasons a timer is included to prevent endless loops when the user stops the transmission or the connection is interrupted by any other reason. In this case a exception will be raised after a predefined timeout.
USAGE =====
Of course it could be possible to simply modify HTTPApp but I don't like to change code of the standard units. So I made a simple unit that installs a new content parser for application/x-www-form-urlencoded content types. Simply add the unit to your USES clause and the fix will be active.
SIDE-EFFECTS ============
Because this is only a workaround, the variable Request.Content may not be correct. This is because the unit cannot modify the Content property of TWebRequest (but it can modify the ContentFields). So, you should not access to the Content property directly if using ChunkedPostFix.pas because this property will still contain the truncated data.
OTHER =====
Feel free to use this unit for whatever you want. I hope it can be useful for you. Please understand I cannot give any warranty that this works. I assume this problem is fixed in Kylix 2.
The unit was made and tested for CGI type applications under Apache (Linux) only but it should work with other web application types as well.
Feel free to contact me if you wish using the e-mail Adress udo@nova-sys.net or visit my web site: www.nova-sys.net