From 200ac3597d6166cb925170444d8ed3714f4ae44e Mon Sep 17 00:00:00 2001 From: wessels <> Date: Wed, 21 Dec 2005 06:22:29 +0000 Subject: [PATCH] Fixed an ICAP bug: Need to handle the case when a REQMOD reply doesn't have any new HTTP headers. --- src/ICAP/ICAPClientReqmodPrecache.cc | 7 ++++- src/ICAP/ICAPModXact.cc | 4 +-- src/client_side_request.cc | 41 +++++++++++++++++----------- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/ICAP/ICAPClientReqmodPrecache.cc b/src/ICAP/ICAPClientReqmodPrecache.cc index 7058a9e2fe..00ffcb7ac3 100644 --- a/src/ICAP/ICAPClientReqmodPrecache.cc +++ b/src/ICAP/ICAPClientReqmodPrecache.cc @@ -110,7 +110,12 @@ void ICAPClientReqmodPrecache::noteSinkAbort(MsgPipe *p) void ICAPClientReqmodPrecache::noteSourceStart(MsgPipe *p) { debug(93,3)("ICAPClientReqmodPrecache::noteSourceStart() called\n"); - assert(adapted->data->header); // What should happen instead? + /* + * If adapted->data->header is NULL then the ICAP response did + * not have a req/res-hdr section. Send the NULL pointer to + * tell the other side to use the original request/response + * headers. + */ http->takeAdaptedHeaders(adapted->data->header); noteSourceProgress(p); } diff --git a/src/ICAP/ICAPModXact.cc b/src/ICAP/ICAPModXact.cc index bd99d9f54d..cc184f5d36 100644 --- a/src/ICAP/ICAPModXact.cc +++ b/src/ICAP/ICAPModXact.cc @@ -690,7 +690,7 @@ void ICAPModXact::parseHttpHead() maybeAllocateHttpMsg(); if (!parseHead(adapted->data->header)) - return; + return; // need more header data } state.parsing = State::psBody; @@ -724,7 +724,7 @@ void ICAPModXact::parseBody() debugs(93, 5, HERE << "have " << readBuf.contentSize() << " body bytes to parse"); - if (gotEncapsulated("res-body")) { + if (gotEncapsulated("res-body") || gotEncapsulated("req-body")) { if (!parsePresentBody()) // need more body data return; } else { diff --git a/src/client_side_request.cc b/src/client_side_request.cc index 2b00457b84..db5608f8c1 100644 --- a/src/client_side_request.cc +++ b/src/client_side_request.cc @@ -1,6 +1,6 @@ /* - * $Id: client_side_request.cc,v 1.54 2005/12/06 00:01:23 wessels Exp $ + * $Id: client_side_request.cc,v 1.55 2005/12/20 23:22:29 wessels Exp $ * * DEBUG: section 85 Client-side Request Routines * AUTHOR: Robert Collins (Originally Duane Wessels in client_side.c) @@ -1120,23 +1120,32 @@ ClientHttpRequest::takeAdaptedHeaders(HttpMsg *msg) assert(cbdataReferenceValid(this)); // indicates bug HttpRequest *new_req = dynamic_cast(msg); - assert(new_req); - /* - * Replace the old request with the new request. First, - * Move the "body_connection" over, then unlink old and - * link new to the http state. - */ - new_req->body_connection = request->body_connection; - request->body_connection = NULL; - requestUnlink(request); - request = requestLink(new_req); + /* - * Store the new URI for logging + * new_req will be NULL if the ICAP response doesn't have new + * request headers for us. Unfortunately, it will also be NULL + * if someone passes us an HttpReply as an HttpMsg, which would + * be a bug. */ - xfree(uri); - uri = xstrdup(urlCanonical(request)); - setLogUri(this, urlCanonicalClean(request)); - assert(request->method); + + if (new_req) { + /* + * Replace the old request with the new request. First, + * Move the "body_connection" over, then unlink old and + * link new to the http state. + */ + new_req->body_connection = request->body_connection; + request->body_connection = NULL; + requestUnlink(request); + request = requestLink(new_req); + /* + * Store the new URI for logging + */ + xfree(uri); + uri = xstrdup(urlCanonical(request)); + setLogUri(this, urlCanonicalClean(request)); + assert(request->method); + } doCallouts(); -- 2.47.3