--------------------- PatchSet 1656 Date: 2005/09/08 07:35:37 Author: rousskov Branch: squid3-icap Tag: (none) Log: - Synced after moving parts common to HttpReply and HttpRequest to HttpMsg. More work is needed to handle REQMOD; search for REQMOD in XXX comments. - Encapsulate "cause" only if it is known. Members: src/ICAPXaction.cc:1.1.2.21->1.1.2.22 src/ICAPXaction.h:1.1.2.10->1.1.2.11 Index: squid3/src/ICAPXaction.cc =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ICAPXaction.cc,v retrieving revision 1.1.2.21 retrieving revision 1.1.2.22 diff -u -r1.1.2.21 -r1.1.2.22 --- squid3/src/ICAPXaction.cc 2 Sep 2005 15:48:12 -0000 1.1.2.21 +++ squid3/src/ICAPXaction.cc 8 Sep 2005 07:35:37 -0000 1.1.2.22 @@ -419,11 +419,11 @@ Must(state.parsingHeaders()); if (state.parsing == State::psIcapHeader) - parseHeader(icapReply); + parseHead(icapReply); if (state.parsing == State::psHttpHeader) { if (gotEncapsulated("res-hdr")) - parseHeader(adapted->data->header); + parseHead(adapted->data->header); else state.parsing = State::psBody; } @@ -434,21 +434,21 @@ adapted->sendSourceStart(); } -void ICAPXaction::parseHeader(HttpReply *header) +void ICAPXaction::parseHead(HttpMsg *head) { - debugs(93, 5, "have " << readBuf.contentSize() << " hdr bytes to parse" << + debugs(93, 5, "have " << readBuf.contentSize() << " head bytes to parse" << "; state: " << state.parsing); http_status error = HTTP_STATUS_NONE; - const bool parsed = header->parse(&readBuf, state.doneReading, &error); + const bool parsed = head->parse(&readBuf, state.doneReading, &error); Must(!error); if (!parsed) { - httpReplyReset(header); + head->reset(); return; } - readBuf.consume(header->hdr_sz); + readBuf.consume(head->hdr_sz); state.parsing = (State::Parsing)(state.parsing + 1); } @@ -619,51 +619,45 @@ void ICAPXaction::makeRequestHeaders(MemBuf *buf) { - HttpRequest *&httpReq = virgin->data->cause; - HttpReply *&httpResp = virgin->data->header; - Must(httpReq); // require request headers for now - Must(httpResp); + // start building ICAP request header; XXX: REQMOD for REQMOD + memBufPrintf(buf, "RESPMOD %s ICAP/1.0\r\n", service->uri); + memBufPrintf(buf, "Host: %s:%d\r\n", service->host, service->port); + memBufPrintf(buf, "Encapsulated:"); MemBuf httpBuf; memBufDefInit(&httpBuf); - /* build HTTP request header */ + // build HTTP request header, if any + if (virgin->data->cause) + encapsulateHead(buf, "req-hdr", &httpBuf, virgin->data->cause); + + // primary HTTP header, if any + if (const MsgPipeData::Header *prime = virgin->data->header) + encapsulateHead(buf, "res-hdr", &httpBuf, prime); // XXX: req-hdr for REQMOD - // HTTP Request-line - memBufPrintf(&httpBuf, "%s %s HTTP/%d.%d\r\n", - RequestMethodStr[httpReq->method], - httpReq->urlpath.size() ? httpReq->urlpath.buf() : "/", - httpReq->http_ver.major, httpReq->http_ver.minor); - - // HTTP Request header fields - Packer p; - packerToMemInit(&p, &httpBuf); - httpHeaderPackInto(&httpReq->header, &p); - packerClean(&p); - httpBuf.append(crlf, 2); // CRLF terminator - const size_t httpRespOffset = httpBuf.contentSize(); - - // build HTTP response header - packerToMemInit(&p, &httpBuf); - httpStatusLinePackInto(&httpResp->sline, &p); - httpHeaderPackInto(&httpResp->header, &p); - packerClean(&p); - httpBuf.append(crlf, 2); // CRLF terminator - const size_t httpBodyOffset = httpBuf.contentSize(); + // update ICAP header; XXX: req-body for REQMOD or null-body! + memBufPrintf(buf, "res-body=%d", httpBuf.contentSize()); - /* ICAP request header */ - memBufPrintf(buf, "RESPMOD %s ICAP/1.0\r\n", service->uri); - memBufPrintf(buf, "Host: %s:%d\r\n", service->host, service->port); - memBufPrintf(buf, "Encapsulated: req-hdr=%d,res-hdr=%d,res-body=%d\r\n", - 0, httpRespOffset, httpBodyOffset); + // finish ICAP header buf->append(crlf, 2); // CRLF terminator - /* ICAP request body */ + // start ICAP request body with encapsulated HTTP headers buf->append(httpBuf.content(), httpBuf.contentSize()); memBufClean(&httpBuf); } +void ICAPXaction::encapsulateHead(MemBuf *icapBuf, const char *section, MemBuf *httpBuf, const HttpMsg *head) { + // update ICAP header + memBufPrintf(icapBuf, "%s=%d,", section, httpBuf->contentSize()); + + // pack HTTP head + Packer p; + packerToMemInit(&p, httpBuf); + head->packInto(&p); + packerClean(&p); +} + bool ICAPXaction::callStart(const char *method) { debugs(93, 5, "ICAPXaction::" << method << " called " << status()); Index: squid3/src/ICAPXaction.h =================================================================== RCS file: /cvsroot/squid-sf//squid3/src/Attic/ICAPXaction.h,v retrieving revision 1.1.2.10 retrieving revision 1.1.2.11 diff -u -r1.1.2.10 -r1.1.2.11 --- squid3/src/ICAPXaction.h 2 Sep 2005 15:27:07 -0000 1.1.2.10 +++ squid3/src/ICAPXaction.h 8 Sep 2005 07:35:37 -0000 1.1.2.11 @@ -1,6 +1,6 @@ /* - * $Id: ICAPXaction.h,v 1.1.2.10 2005/09/02 15:27:07 rousskov Exp $ + * $Id: ICAPXaction.h,v 1.1.2.11 2005/09/08 07:35:37 rousskov Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -49,6 +49,8 @@ class ChunkedCodingParser; +class HttpMsg; + class ICAPXaction: public MsgPipeSource, public MsgPipeSink { @@ -93,7 +95,7 @@ void parseMore(); void parseHeaders(); - void parseHeader(HttpReply *header); + void parseHead(HttpMsg *head); void parseBody(); bool parsePresentBody(); @@ -114,6 +116,8 @@ private: // returns a temporary string depicting transaction status, for debugging const char *status() const; + + void encapsulateHead(MemBuf *icapBuf, const char *section, MemBuf *httpBuf, const HttpMsg *head); bool gotEncapsulated(const char *section) const; Pointer self;