// send check header "X-CC-DOWN-CHECK" to lower FC static int SendCheckHeader(clientHttpRequest *http) { // do not send X-CC-UP-CHECK to client as possible httpHeaderDelByName(&http->reply->header, "X-CC-UP-CHECK"); struct mod_conf_param *cfg = cc_get_mod_param(http->conn->fd, mod); if (NULL == cfg || !cfg->send) { debug(107,3)("mod_check_response: no need to send X-CC-UP-CHECK header\n"); return -1; } const char *down_buf = httpHeaderGetValue(&http->request->header, "X-CC-DOWN-CHECK"); if (NULL == down_buf) { if (cfg->send) debug(107,2)("mod_check_response: do not send X-CC-UP-CHECK header, for not received X-CC-DOWN-CHECK header\n"); return -1; } char key[512]; memset(key, 0, 512); unsigned char md5[SQUID_MD5_DIGEST_LENGTH]; memset(md5, 0, SQUID_MD5_DIGEST_LENGTH); strncpy(key, down_buf, 511); char *host = key + strlen(key); url2host(host, http->uri); GetMD5Digest(key, md5); assert(cfg->send); httpHeaderAddEntry(&http->reply->header, httpHeaderEntryCreate(HDR_OTHER, "X-CC-UP-CHECK", (char*)md5)); debug(107, 3)("mod_check_response: send X-CC-UP-CHECK=[%s] header to client\n", md5); return 0; }
/* add extension header (these fields are not parsed/analyzed/joined, etc.) */ void httpHeaderPutExt(HttpHeader * hdr, const char *name, const char *value) { assert(name && value); debug(55, 8) ("%p adds ext entry '%s: %s'\n", hdr, name, value); httpHeaderAddEntry(hdr, httpHeaderEntryCreate(HDR_OTHER, name, value)); }
void httpHeaderPutStr(HttpHeader * hdr, http_hdr_type id, const char *str) { assert_eid(id); assert(Headers[id].type == ftStr); /* must be of an appropriate type */ assert(str); httpHeaderAddEntry(hdr, httpHeaderEntryCreate(id, NULL, str)); }
void httpHeaderPutTime(HttpHeader * hdr, http_hdr_type id, time_t htime) { assert_eid(id); assert(Headers[id].type == ftDate_1123); /* must be of an appropriate type */ assert(htime >= 0); httpHeaderAddEntry(hdr, httpHeaderEntryCreate(id, NULL, mkrfc1123(htime))); }
void httpHeaderPutInt(HttpHeader * hdr, http_hdr_type id, int number) { assert_eid(id); assert(Headers[id].type == ftInt); /* must be of an appropriate type */ assert(number >= 0); httpHeaderAddEntry(hdr, httpHeaderEntryCreate(id, NULL, xitoa(number))); }
void httpHeaderPutSize(HttpHeader * hdr, http_hdr_type id, squid_off_t number) { char size[64]; assert_eid(id); assert(Headers[id].type == ftSize); /* must be of an appropriate type */ assert(number >= 0); snprintf(size, sizeof(size), "%" PRINTF_OFF_T, number); httpHeaderAddEntry(hdr, httpHeaderEntryCreate(id, NULL, size)); }
void httpHeaderPutRange(HttpHeader * hdr, const HttpHdrRange * range) { MemBuf mb; Packer p; assert(hdr && range); /* remove old directives if any */ httpHeaderDelById(hdr, HDR_RANGE); /* pack into mb */ memBufDefInit(&mb); packerToMemInit(&p, &mb); httpHdrRangePackInto(range, &p); /* put */ httpHeaderAddEntry(hdr, httpHeaderEntryCreate(HDR_RANGE, NULL, mb.buf)); /* cleanup */ packerClean(&p); memBufClean(&mb); }
void httpHeaderPutCc(HttpHeader * hdr, const HttpHdrCc * cc) { MemBuf mb; Packer p; assert(hdr && cc); /* remove old directives if any */ httpHeaderDelById(hdr, HDR_CACHE_CONTROL); /* pack into mb */ memBufDefInit(&mb); packerToMemInit(&p, &mb); httpHdrCcPackInto(cc, &p); /* put */ httpHeaderAddEntry(hdr, httpHeaderEntryCreate(HDR_CACHE_CONTROL, NULL, mb.buf)); /* cleanup */ packerClean(&p); memBufClean(&mb); }
// send a special header to upper FC static int SendRandomNumber(HttpStateData *httpState, HttpHeader* hdr) { struct mod_conf_param *cfg = cc_get_mod_param(httpState->fd, mod); if (NULL == cfg) return -1; struct timeval tp; if (gettimeofday(&tp, NULL)) { debug(107, 2)("mod_check_response: gettimeofday error\n"); return -1; } struct send_random *data = cc_get_mod_private_data(FWDSTATE_PRIVATE_DATA, httpState->fwd, mod); if (!data) { data = xcalloc(1, sizeof(struct send_random)); snprintf(data->number, 10, "%ld", tp.tv_usec); cc_register_mod_private_data(FWDSTATE_PRIVATE_DATA, httpState->fwd, data, free_random, mod); httpHeaderAddEntry(hdr, httpHeaderEntryCreate(HDR_OTHER, "X-CC-DOWN-CHECK", data->number)); debug(107,3)("mod_check_response: send X-CC-DOWN-CHECK=[%s] to orgin\n", data->number); } return 0; }
HttpHeaderEntry * httpHeaderEntryClone(const HttpHeaderEntry * e) { return httpHeaderEntryCreate(e->id, strBuf(e->name), strBuf(e->value)); }