FastCGI的:检索请求头 [英] FastCGI: retrieve the request headers

查看:429
本文介绍了FastCGI的:检索请求头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用FastCGI与Apache和mod_fcgid一个Web C ++应用程序。

I’m currently working on a Web C++ application using FastCGI with Apache and mod_fcgid.

我想检索请求的头,但是我没有找到如何做到这一点。一些研究之后,我还以为头是在FCGX_Request属性envp,但它包含环境变量,例如:

I’m trying to retrieve the headers of a request, but I didn’t find how to do so. After some researches, I thought the headers were in the attribute "envp" of "FCGX_Request", but it contains environment variables such as:

REMOTE_ADDR: 192.168.0.50
SERVER_SOFTWARE: Apache/2.2.21 (Unix) mod_ssl/2.2.21 OpenSSL/1.0.0f DAV/2 mod_fcgid/2.3.6
REDIRECT_UNIQUE_ID: TxytP38AAAEAABpcDskAAAAE
FCGI_ROLE: RESPONDER
HTTP_ACCEPT_LANGUAGE: fr
SERVER_SIGNATURE: <address>Apache/2.2.21 [etc.]

这些变量给我有用的信息,但我需要真正的HTTP报头,特别是曲奇。我试图对FCGX_Request流,在读,但它似乎是请求体(POST DATAS)。由于我的应用程序需要是多线程的,我用FCGX_Accept_r(),像这样的:

These variables offer me useful informations, but I need the real HTTP headers, and especially "Cookie". I tried to read on the stream "in" of the "FCGX_Request" but it seems to be for the request body (POST datas). As my application is intended to be multi-threaded, I use "FCGX_Accept_r()", like this:

while(true)
{
    FCGX_Init();
    FCGX_Request* fcgiRequest = new FCGX_Request;
    FCGX_InitRequest(fcgiRequest, 0, 0);

    if(FCGX_Accept_r(fcgiRequest) < 0)
        break;

    Request* request = new Request(fcgiRequest);
    request->process();
}

但其实,我不使用线程。请求执行一前一后。

But actually, I don’t use threads. Requests are executed one after the other.

我怎样才能获得请求头?

How can I get the request headers?

感谢您。

推荐答案

请尝试以下code。它应该打印出整个环境,所以你可以找到你正在寻找的变量。

Try the following code. It should print out the entire environment so you can find the variable you are looking for.

while(true)
{
    FCGX_Init();
    FCGX_Request* fcgiRequest = new FCGX_Request;
    FCGX_InitRequest(fcgiRequest, 0, 0);

    if(FCGX_Accept_r(fcgiRequest) < 0)
        break;

    char **env = fcgiRequest->envp;
    while (*(++env))
        puts(*env);


    Request* request = new Request(fcgiRequest);
    request->process();
}

这篇关于FastCGI的:检索请求头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆