Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法识别CURL apache模块中的自定义头_C_Apache_Loops_Redirect_Curl - Fatal编程技术网

无法识别CURL apache模块中的自定义头

无法识别CURL apache模块中的自定义头,c,apache,loops,redirect,curl,C,Apache,Loops,Redirect,Curl,这是我目前掌握的代码。请忽略未使用的变量,因为我只显示重要的代码片段: typedef struct{ char* rheaders[500][500]; //HTML headers char* curltemp[50000]; //Temp string space for CURL function char* alias[5000]; char* idx[5000]; char* redirurl[5000]; unsigned lo

这是我目前掌握的代码。请忽略未使用的变量,因为我只显示重要的代码片段:

typedef struct{
    char* rheaders[500][500]; //HTML headers
    char* curltemp[50000];    //Temp string space for CURL function
    char* alias[5000];
    char* idx[5000];
    char* redirurl[5000];
    unsigned long rhdrct;
    unsigned long idxct;
    unsigned long aliasct;
    unsigned long notrail;
    unsigned long nologall;
    unsigned long httpstatus;
    unsigned long print;
}Iconfig;
static Iconfig conf;
static CURL *curl;

static size_t curlH(char *buffer,size_t size,size_t nitems,void *userdata){
    //store data as it comes in. This works
    snprintf((char*)conf.rheaders[conf.rhdrct++],(size*nitems)-1,"%s\0",(char*)buffer);
    return (size*nitems);
}

static int getnewURL(request_rec *r){
    curl=curl_easy_init();
    if (curl){
        struct curl_slist *chunk=NULL;char cc[1000];
        //This header below isn't being sent with request
        chunk = curl_slist_append(chunk, "x-custom: 1;"); 
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, chunk);
        //Request from server this code is executed on
        curl_easy_setopt(curl, CURLOPT_URL, "http://127.0.0.1/test");
        curl_easy_setopt(curl, CURLOPT_MAXREDIRS, 10L);
        curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
        curl_easy_setopt(curl, CURLOPT_HEADERDATA,conf.curltemp);
        curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION,curlH);
        CURLcode res=curl_easy_perform(curl);
        curl_easy_cleanup(curl);
        //iterate and display all headers after request is done
        ap_log_error(APLOG_MARK, APLOG_CRIT, 0, r->server, "Headers...");
        unsigned long i;
        for (i=0;i<conf.rhdrct;i++){
            ap_log_error(APLOG_MARK, APLOG_CRIT, 0, r->server, "%d %s",i,conf.rheaders[i]);
        }
    }
}

static int handler(request_rec *r){
    // This happens on every request including those from CURL
    if (!ap_is_initial_req(r)){return DECLINED;}
    //check headers to see if x-custom is set to 1
    const char*a=apr_table_get(r->headers_in,"x-custom"); 
    if (a){
        if (strcmp("1",a)==0){
            //pass on new x-received header sent via CURL and process normally
            //but this stage never happens
            char b[1000];sprintf(b,"%s recvd\0",a);
            apr_table_set(r->headers_out,"x-received:",b);
            ap_log_error(APLOG_MARK, APLOG_CRIT, 0, r->server, "Subrequest");
            return DECLINED;
        }
    }
    //execute request in CURL and stop this apache process
    getnewURL(r);
    return DONE;
}
typedef结构{
char*rheaders[500][500];//HTML标题
char*curltemp[50000];//CURL函数的临时字符串空间
字符*别名[5000];
char*idx[5000];
char*redirl[5000];
无符号长rhdrct;
无符号长idxct;
无符号长锯齿ct;
无符号长钢轨;
未签名的长诺洛加;
未签名的长httpstatus;
无符号长打印;
}Iconfig;
静态Iconfig配置;
静态旋度*旋度;
静态大小(char*缓冲区、大小、大小单位、void*用户数据){
//在数据进入时存储数据。这很有效
snprintf((char*)conf.rhaders[conf.rhdrct++],(size*nitems)-1,“%s\0”,(char*)缓冲区);
返回(大小*单位);
}
静态int getnewURL(请求记录*r){
curl=curl_easy_init();
if(curl){
struct curl_slist*chunk=NULL;char cc[1000];
//以下标题未随请求一起发送
chunk=curl\u slist\u append(chunk,“x-custom:1;”);
curl\u easy\u setopt(curl,CURLOPT\u HTTPHEADER,chunk);
//来自服务器的请求此代码在其上执行
curl\u easy\u setopt(curl,CURLOPT\u URL,“http://127.0.0.1/test");
curl_easy_setopt(curl,CURLOPT_MAXREDIRS,10L);
卷曲位置(卷曲,卷曲位置,1L);
curl_easy_setopt(curl,CURLOPT_HEADERDATA,conf.curlttemp);
curl_easy_setopt(curl,CURLOPT_HEADERFUNCTION,curlH);
CURLcode res=curl\u easy\u perform(curl);
旋度\轻松\清洁(旋度);
//请求完成后,迭代并显示所有标题
ap_日志_错误(APLOG_标记,APLOG_临界值,0,r->服务器,“标题…”);
无符号长i;
对于(i=0;iserver,“%d%s”,i,conf.rheaders[i]);
}
}
}
静态整型处理程序(请求记录*r){
//这会发生在每个请求上,包括来自CURL的请求
如果(!ap_是_initial_req(r)){返回已拒绝;}
//检查标题以查看x-custom是否设置为1
const char*a=apr_table_get(r->headers_in,“x-custom”);
如果(a){
如果(strcmp(“1”,a)==0){
//传递通过CURL发送的新x接收头并正常处理
//但这一阶段从未发生过
字符b[1000];sprintf(b,“%s recvd\0”,a);
apr\u表格集(r->headers\u out,“x-received:”,b);
ap_日志_错误(APLOG_标记,APLOG_临界值,0,r->服务器,“子请求”);
回报率下降;
}
}
//在CURL中执行请求并停止此apache进程
getnewURL(r);
已完成的返回;
}
我设法通过我的代码从不同的URL检索标准头,但我想做的是插入一个头,通过我的服务器URL域(127.0.0.1)再次将其传递给我的代码,并使用该头确定curl是否至少执行过一次。如果我没有正确地执行此操作,那么将执行越来越多的处理程序函数,从而导致apache服务器锁定

我的最终目标是创建一个内部重定向系统,这样当来宾从服务器请求一个导致http 301状态重定向的URL到导致另一个http 301状态重定向的URL时,服务器将合并这些重定向,这样用户只需忍受一个重定向

我的问题在于
//但是这个阶段从来没有发生过


有没有人知道我如何解决这个问题,或者有没有人有更好的方法让apache模块(处理函数)识别传入的URL请求来自我的getnewURL函数?

Nevermind。我想出来了。我在apache配置文件中有以下设置:

MinSpareServers 1
MaxSpareServers 1
MaxClients 1
StartServers 1

然后我把数字从1改为5,现在一切正常了。我想出来了。我在apache配置文件中有以下设置:

MinSpareServers 1
MaxSpareServers 1
MaxClients 1
StartServers 1
然后我把数字从1改为5,现在一切正常了