Search code examples
capachefastcgi

Missing characters from input stream from fastcgi request


I'm trying to develop simple RESTful api using FastCGI (and restcgi). When I tried to implement POST method I noticed that the input stream (representing request body) is wrong. I did a little test and looks like when I try to read the stream only every other character is received.

Body sent: name=john&surname=smith Received: aejh&unm=mt

I've tried more clients just to make sure it's not the client messing with the data. My code is:

int main(int argc, char* argv[]) {
  // FastCGI initialization.
  FCGX_Init();
  FCGX_Request request;
  FCGX_InitRequest(&request, 0, 0); 

  while (FCGX_Accept_r(&request) >= 0) {
    // FastCGI request setup.
    fcgi_streambuf fisbuf(request.in);
    std::istream is(&fisbuf);
    fcgi_streambuf fosbuf(request.out);
    std::ostream os(&fosbuf);

    std::string str;
    is >> str;
    std::cerr << str;  // this way I can see it in apache error log

    // restcgi code here
  }   

  return 0;
}

I'm using fast_cgi module with apache (not sure if that makes any difference).

Any idea what am I doing wrong?


Solution

  • After finding no answer anywhere (not even FastCGI mailing list) I dumped the original fastcgi libraries and tried using fastcgi++ libraries instead. The problem disappeared. There are also other benefits - c++, more features, easier to use.