[fpc-pascal] Premature end of headers using fcl-web and POST

Felipe Monteiro de Carvalho felipemonteiro.carvalho at gmail.com
Mon Oct 31 16:15:00 CET 2011


Hello,

So I advanced my CGI using HTTP GET so far, but I'd like to migrate to
HTTP POST. But I always get this error message in the apache logs:

Premature end of script headers: openpoker3.cgi, referer:
http://localhost:8080/cgi-bin/openpoker3.cgi?module=MainPage

The request doesn't even get to my handler in the CGI =(

Here is my JavaScript which initiates the communication:

  SendSyncRequestViaGet = function(RequestURL, RequestContent)
  {
    var request = new XMLHttpRequest();
    request.open('GET', RequestURL+"&data="+RequestContent, false);
    request.setRequestHeader('Content-Type', 'text/html');
    request.send("");
    //debugDiv.innerHTML = debugDiv.innerHTML + "after send<br>";
    return request.responseText;
  }

  SendSyncRequestViaPost = function(RequestURL, RequestContent)
  {
    var request = new XMLHttpRequest();
    request.open('POST', RequestURL, false);
    request.setRequestHeader('Content-Type', 'text/html');
    request.setRequestHeader("Content-length", RequestContent.length);
    request.setRequestHeader("Connection", "close");
    debugDiv.innerHTML = debugDiv.innerHTML + "before send<br>";
    request.send(RequestContent);
    debugDiv.innerHTML = debugDiv.innerHTML + "after send<br>";
    return request.responseText;
  }

  var lobbyTimer;

  function lobbyTimerCallback()
  {
    // Load all Lobby table data
    var tableInnerHTML =
SendSyncRequestViaPost("openpoker3.cgi?module=PokerServer","00_FFFFFFFFFFFFFFFF_0000002E_00000000_");
 ...

If I just use SendSyncRequestViaGet then everything goes fine. If I
use Post, I get apache errors and that previously mentioned message in
the Apache log.

The JavaScript executes correctly as I already verified, and the error
is not in my Handler code, because it doesn't even get there.

Any ideas? I am sure that the JavaScript code is correct, because if I
substitute my program main with this:

var
  Strings: TStringList;
  i: Integer;
begin
  Strings:= TStringList.Create;
  Strings.LoadFromFile(ExtractFilePath(ParamStr(0)) + 'mainpage.html');
  WriteLn('Content-Type: text/html');
  WriteLn('');
  for i := 0 to Strings.Count-1 do
    WriteLn(Strings.Strings[i]);
  try
  OPDebugLn('[AAA]');
  Application.Initialize;
  OPDebugLn('[B]');
  Application.Run;
  OPDebugLn('[C]');
  except
    OPDebugLn('[D]');
  end;
end.

And then the POST works fine! But of course that I destroyed fcl-web then...

Updating to a recent 2.5 didn't help. I tryed to rebuild fcl-web with
cgidebug but I couldn't find any trace of an output log.

There is no exception. It just runs fine and doesn't call my module
and does not print any error messages, does not print anything after
the headers actually =(

Any ideas are welcome...

thanks,
-- 
Felipe Monteiro de Carvalho



More information about the fpc-pascal mailing list