CGI programs/closing connection

Discussion in 'Apache' started by wontcommentonthis, Jan 4, 2008.

  1. #1
    Hi!

    First of all, this is my first post here, so please bear with me :)

    I installed Apache on my Linux server - works just fine. I decided to code my own CGI program in C++ (since I worked with C++ for years now). It works perfectly, I can read forms, print out HTTP headers and HTML content. No problem. But: there is function in my code that checks whether the HTTP request comes from an untrusted source. If my function decides that the source is not trustworthy, I want my CGI program to signal Apache to IMMEDIATELY disconnect WITHOUT sending any headers, or content.

    And this is my question: How can I tell Apache to disconnect from the User Agent?

    I tried the following:
    1) Send nothing at all to standard output: Apache sends a 500 error bc of premature headers

    2) Return an exit status different from 0 to the shell (which should signal an error): doesn't work, apache still sends the response.

    So how can I do it? (Please note, that I don't want to change my Apache httpd.conf in any way to filter untrustworthy requests. My own C++ functions should be able to dynamically decide whether to close or to keep the request alive.)

    Also, and that is my second and last question, how can I read the complete, unparsed headers sent by the user agent? Because the environment variables only contain parsed information.

    Thanks in advance for every helpful response. :)
     
    wontcommentonthis, Jan 4, 2008 IP