static int func_http_repl_send_start(clientHttpRequest *http) { assert(http); if (0 == http->request->flags.redirected) return -1; HttpHeader *hdr = &http->reply->header; HttpHeaderEntry e; stringInit(&e.name,"Content-Disposition"); stringInit(&e.value,"attachment; filename=\""); char *filename = strrchr(http->uri, '/'); if (NULL == filename) return -1; filename++; stringAppend(&e.value, filename, strlen(filename)); stringAppend(&e.value, "\"", 1); e.id = HDR_CONTENT_DISPOSITION; httpHeaderDelById(hdr, e.id); httpHeaderAddEntry(hdr, httpHeaderEntryClone(&e)); stringClean(&e.name); stringClean(&e.value); return 0; }
/* append entries (also see httpHeaderUpdate) */ void httpHeaderAppend(HttpHeader * dest, const HttpHeader * src) { const HttpHeaderEntry *e; HttpHeaderPos pos = HttpHeaderInitPos; assert(src && dest); assert(src != dest); debug(55, 7) ("appending hdr: %p += %p\n", dest, src); while ((e = httpHeaderGetEntry(src, &pos))) { httpHeaderAddEntry(dest, httpHeaderEntryClone(e)); } }
/* *This line is to modify the header */ static int mod_modify_s2o_header(HttpStateData* data, HttpHeader* hdr) { assert(data); int fd = data->fd; int i, len; struct mod_conf_param *param = (struct mod_conf_param *)cc_get_mod_param(fd, mod); assert(param); debug(107, 3)("param->orig_name=%s, param->new_name=%s\n", strBuf(param->orig_name), strBuf(param->new_name)); HttpHeaderPos pos = HttpHeaderInitPos; HttpHeaderEntry *myheader; HttpHeaderEntry e; while ((myheader = httpHeaderGetEntry(hdr, &pos))) { debug(107, 3)("myheader=%s, param->new_name=%s\n", strBuf(myheader->name), strBuf(param->new_name)); if (strCaseCmp(myheader->name, strBuf(param->orig_name)) == 0) { debug(107, 3)("%s is myheader->value,%s is param->orig_name\n",strBuf(myheader->value), strBuf(param->orig_name)); if(strLen(myheader->value) >= 4095) { debug(107, 3)("A too long header value!!\n"); return -1; } stringInit(&e.name, strBuf(param->new_name)); stringInit(&e.value, myheader->value.buf); len=strlen(strBuf(e.name)); i=httpHeaderIdByNameDef(strBuf(e.name), len); if(-1 == i) e.id = HDR_OTHER; else e.id = i; httpHeaderDelByName(hdr, strBuf(param->orig_name)); httpHeaderAddEntry(hdr, httpHeaderEntryClone(&e)); //httpHeaderDelAt(&request->header, pos); //httpHeaderRefreshMask(&request->header); //httpHeaderInsertEntry(&request->header, httpHeaderEntryClone(&e), pos); stringClean(&e.name); stringClean(&e.value); break; } } return 0; }
/* use fresh entries to replace old ones */ void httpHeaderUpdate(HttpHeader * old, const HttpHeader * fresh, const HttpHeaderMask * denied_mask) { const HttpHeaderEntry *e; HttpHeaderPos pos = HttpHeaderInitPos; assert(old && fresh); assert(old != fresh); debug(55, 7) ("updating hdr: %p <- %p\n", old, fresh); while ((e = httpHeaderGetEntry(fresh, &pos))) { /* deny bad guys (ok to check for HDR_OTHER) here */ if (denied_mask && CBIT_TEST(*denied_mask, e->id)) continue; httpHeaderDelByName(old, strBuf(e->name)); httpHeaderAddEntry(old, httpHeaderEntryClone(e)); } }
/*if the origindomain doesn't need cookie,this part is not neccessary * static int update_cookie_direction_0(clientHttpRequest *http) { assert(http); assert(http->request); const char head_name_request[20] = "Cookie"; int len = strlen(head_name_request); int flag = 0; HttpHeaderPos pos = HttpHeaderInitPos; request_t* request = http->request; char *uri = http->uri; char cookie_value[100]="0"; char cookie_primary_key_name[20]; char cookie_sub_key_name[20]; int i = 0; debug(139,3)("in update_cookie_direction_0 receive uri %s\n",uri); HttpHeaderEntry e; HttpHeaderEntry *myheader; stringInit(&e.name, head_name_request); i = httpHeaderIdByNameDef(head_name_request, len); e.id = i; if (-1 == i) e.id = HDR_OTHER; while ((myheader = httpHeaderGetEntry(&request->header, &pos))) { if (strCaseCmp(myheader->name, head_name_request) == 0) { debug(139, 3)("%s is myheader->value,%s is name\n",myheader->value.buf,myheader->name.buf); flag = 1; } } debug(139,3)("flag=%d\n",flag); if(!flag) { if(0 == get_param_from_uri(uri,cookie_primary_key_name,cookie_sub_key_name)) { return 1; } to_upper(cookie_primary_key_name); snprintf(cookie_value,100,"%s:(FM%s=0)",cookie_primary_key_name,cookie_sub_key_name); debug(139,3)("cookie value is %s\n",cookie_value); debug(139,3)("cookie_primary_key_name is %s\n",cookie_primary_key_name); debug(139,3)("cookie_sub_key_name is %s\n",cookie_sub_key_name); stringInit(&e.value, cookie_value); httpHeaderAddEntry(&request->header, httpHeaderEntryClone(&e)); } return 1; } */ static int update_cookie_direction_3(clientHttpRequest *http) { assert(http); assert(http->request); // const char head_name_request[20] = "Cookie"; const char head_name_reply[20] = "Set-Cookie"; // int len = strlen(head_name_reply); // int flag = 0; // HttpHeaderPos pos = HttpHeaderInitPos; // request_t* request = http->request; HttpReply* reply = http->reply; char *uri = http->uri; // char cookie_value[MAX_NAME_SIZE] = "0"; // char cookie_value_from_url[MAX_NAME_SIZE] = "0 "; char cookie_primary_key_name[MAX_NAME_SIZE] = "0"; char cookie_sub_key_name[MAX_NAME_SIZE] = "0"; char cookie_file_name[MAX_NAME_SIZE] = "0"; debug(139,3)("in update_cookie_direction_3 receive uri %s\n",uri); HttpHeaderEntry e; // HttpHeaderEntry *myheader; stringInit(&e.name, head_name_reply); // i = httpHeaderIdByNameDef(head_name_reply, len); // e.id = i; e.id = HDR_SET_COOKIE; // if (-1 == i) // e.id = HDR_OTHER; /* while ((myheader = httpHeaderGetEntry(&request->header, &pos))) { if (strCaseCmp(myheader->name, head_name_request) == 0) { debug(139, 3)("%s is myheader->value,%s is name\n",myheader->value.buf,myheader->name.buf); flag = 1; strcpy(cookie_value,myheader->value.buf); debug(139,5)("cookie_value =%s\n",cookie_value); if(0 == deal_with_cookie(cookie_value)) { debug(139,3)("Cookie format is wrong\n"); return 0; } if(0 == get_param_from_uri(uri,cookie_primary_key_name,cookie_sub_key_name)) { debug(139,3)("get_param_from_uri error\n"); return 0; } to_upper(cookie_primary_key_name); snprintf(cookie_value_from_url,100,"%s:(FM%s=",cookie_primary_key_name,cookie_sub_key_name); debug(139,5)("cookie_value_from_url is %s\n",cookie_value_from_url); if(strncmp(cookie_value,cookie_value_from_url,strlen(cookie_value_from_url))) { debug(139,3)("get_param_from_uri cookie_value_from_url doesn't match cookie_value\n"); return 0; } } } */ if(reply->sline.status >= HTTP_OK && reply->sline.status < HTTP_BAD_REQUEST ) { if(0 == get_param_from_uri(uri,cookie_primary_key_name,cookie_sub_key_name,cookie_file_name)) { debug(139,3)("get_param_from_uri error\n"); stringClean(&e.name); return 0; } struct tm *ptr; ptr = gmtime(&reply->expires); debug(139,3)("expires = %s\n", asctime(ptr)); char tmpbuf[128]; char cookie_value[MAX_HEADER_SIZE]; strftime( tmpbuf, 128, "%a, %d %b %G %T GMT \n", ptr); debug(139,3)("expires = %s\n", tmpbuf); snprintf(cookie_value,MAX_HEADER_SIZE,"DTAG=CAM=%s&LOC=%s&CRT=%s; expires=%s; path=/",cookie_primary_key_name,cookie_sub_key_name,cookie_file_name,tmpbuf); debug(139,5)("cookie value is %s\n",cookie_value); stringInit(&e.value, cookie_value); httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e)); stringClean(&e.value); } else { ;//do nothing } stringClean(&e.name); return 1; }
/* *?????Ǵ????ġ?????һ??header?Ĵ??�?? */ static int modifyHeader3(struct action_part* acp, HttpReply* reply) { assert(acp); assert(reply); int flag = 0; int act = acp->action; struct header_info* hdr = acp->hdr; HttpHeaderEntry e; //HttpHeaderEntry *mye; int i; HttpHeaderEntry *myheader; HttpHeaderPos pos = HttpHeaderInitPos + HDR_ENUM_END; e.name = stringDup(&hdr->header); e.value = stringDup(&hdr->value); i = httpHeaderIdByNameDef(strBuf(hdr->header), strLen(hdr->header)); e.id = i; if(i == -1) { e.id = HDR_OTHER; if(0 == act) { httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e)); } else if(2 == act) { while ((myheader = httpHeaderGetEntryPlus(&reply->header, &pos))) { if (myheader->id == HDR_OTHER && strCaseCmp(myheader->name, strBuf(hdr->header)) == 0) { debug(98, 3)("%s is myheader->value,%s is hdr->value\n",strBuf(myheader->value), strBuf(hdr->value)); stringReset(&myheader->value, strBuf(hdr->value)); } } } else if(1 == act) { httpHeaderDelByName(&reply->header,strBuf(hdr->header)); } else if(3 == act) { while ((myheader = httpHeaderGetEntryPlus(&reply->header, &pos))) { if (myheader->id == HDR_OTHER && strCaseCmp(myheader->name, strBuf(hdr->header)) == 0) { debug(98, 3)("%s is myheader->value,%s is hdr->value\n",strBuf(myheader->value), strBuf(hdr->value)); flag = 1; stringReset(&myheader->value, strBuf(hdr->value)); } } if(!flag) httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e)); } } else { //mye = httpHeaderFindEntry2(&reply->header, i); //debug(98, 3) ("%d is i\n", i); if(0 == act) { httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e)); } else if(2 == act) { if(httpHeaderDelByName(&reply->header,strBuf(hdr->header))) { httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e)); } //mye = httpHeaderFindEntry2(&reply->header, i); //debug(98, 3)("%s is newvalue\n",strBuf(mye->value)); } else if(1 == act) { httpHeaderDelByName(&reply->header,strBuf(hdr->header)); } else if(3 == act) { httpHeaderDelByName(&reply->header,strBuf(hdr->header)); httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e)); } } stringClean(&e.name); stringClean(&e.value); return 0; }
void httpHeaderAddClone(HttpHeader * hdr, const HttpHeaderEntry * e) { httpHeaderAddEntry(hdr, httpHeaderEntryClone(e)); }