PRB: CGI Application Hangs When Reading Data Posted from Browser (189280)



The information in this article applies to:

  • Microsoft Internet Explorer (Programming) 4.0

This article was previously published under Q189280

SYMPTOMS

When data is posted from the Internet Explorer to a CGI application, the browser will display an hourglass. At some point, the browser will time out and display an error message indicating that it has done so.

CAUSE

The behavior of the Internet Explorer was changed with Internet Explorer 4.0 to more closely reflect the HTTP specification (RFC 2068). This comment is taken from RFC 2068.

NOTE: Certain buggy HTTP/1.0 client implementations generate an extra CRLFs after a POST request. To restate what is explicitly forbidden by the BNF, an HTTP/1.1 client must not preface or follow a request with an extra CRLF.

CGI applications that rely on the CRLF will not work correctly with Internet Explorer 4.0. The following code is an example that will fail:
      if (!gets(cgiinput)) {
      printf("Couldn't read CGI input from STDIN.\n") ;
      exit(1) ;
   }
				
Data posted to a CGI application is read by the CGI application from STDIN. The gets() call above causes the CGI application to hang as it is dependant on the CRLF.

RESOLUTION

A well-behaved CGI application will read exactly the number of bytes specified by the browser in the content-length header. The following code behaves correctly:
   if ( !(content_length = atoi(getenv("CONTENT_LENGTH"))) ) {
      printf("No Content-Length was sent with the POST request.\n") ;
      exit(1) ;
   }

   if (!fread(cgiinput, content_length, 1, stdin)) {
      printf("Couldn't read CGI input from STDIN.\n") ;
      exit(1) ;
   }
				

STATUS


Modification Type:MajorLast Reviewed:9/1/1999
Keywords:kbprb KB189280