5 * DEBUG: section 11 Hypertext Transfer Protocol (HTTP)
6 * AUTHOR: Harvest Derived
8 * SQUID Web Proxy Cache http://www.squid-cache.org/
9 * ----------------------------------------------------------
11 * Squid is the result of efforts by numerous individuals from
12 * the Internet community; see the CONTRIBUTORS file for full
13 * details. Many organizations have provided support for Squid's
14 * development; see the SPONSORS file for full details. Squid is
15 * Copyrighted (C) 2001 by the Regents of the University of
16 * California; see the COPYRIGHT file for full details. Squid
17 * incorporates software developed and/or copyrighted by other
18 * sources; see the CREDITS file for full details.
20 * This program is free software; you can redistribute it and/or modify
21 * it under the terms of the GNU General Public License as published by
22 * the Free Software Foundation; either version 2 of the License, or
23 * (at your option) any later version.
25 * This program is distributed in the hope that it will be useful,
26 * but WITHOUT ANY WARRANTY; without even the implied warranty of
27 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28 * GNU General Public License for more details.
30 * You should have received a copy of the GNU General Public License
31 * along with this program; if not, write to the Free Software
32 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
37 * Anonymizing patch by lutz@as-node.jena.thur.de
38 * have a look into http-anon.c to get more informations.
43 #include "acl/FilledChecklist.h"
45 #include "auth/UserRequest.h"
47 #include "base/AsyncJobCalls.h"
48 #include "base/TextException.h"
50 #include "comm/Write.h"
52 #include "DelayPools.h"
54 #include "err_detail_type.h"
55 #include "errorpage.h"
57 #include "HttpControlMsg.h"
58 #include "HttpHdrContRange.h"
59 #include "HttpHdrSc.h"
60 #include "HttpHdrScTarget.h"
61 #include "HttpReply.h"
62 #include "HttpRequest.h"
64 #include "MemObject.h"
67 #include "SquidTime.h"
71 #define SQUID_ENTER_THROWING_CODE() try {
72 #define SQUID_EXIT_THROWING_CODE(status) \
75 catch (const std::exception &e) { \
76 debugs (11, 1, "Exception error:" << e.what()); \
80 CBDATA_CLASS_INIT(HttpStateData
);
82 static const char *const crlf
= "\r\n";
84 static void httpMaybeRemovePublic(StoreEntry
*, http_status
);
85 static void copyOneHeaderFromClientsideRequestToUpstreamRequest(const HttpHeaderEntry
*e
, const String strConnection
, HttpRequest
* request
, const HttpRequest
* orig_request
,
86 HttpHeader
* hdr_out
, const int we_do_ranges
, const http_state_flags
);
88 HttpStateData::HttpStateData(FwdState
*theFwdState
) : AsyncJob("HttpStateData"), ServerStateData(theFwdState
),
89 lastChunk(0), header_bytes_read(0), reply_bytes_read(0),
90 body_bytes_truncated(0), httpChunkDecoder(NULL
)
92 debugs(11,5,HERE
<< "HttpStateData " << this << " created");
93 ignoreCacheControl
= false;
94 surrogateNoStore
= false;
97 readBuf
->init(16*1024, 256*1024);
98 orig_request
= HTTPMSGLOCK(fwd
->request
);
100 // reset peer response time stats for %<pt
101 orig_request
->hier
.peer_http_request_sent
.tv_sec
= 0;
102 orig_request
->hier
.peer_http_request_sent
.tv_usec
= 0;
105 _peer
= fwd
->servers
->_peer
; /* might be NULL */
110 if (_peer
->options
.originserver
)
111 url
= orig_request
->urlpath
.termedBuf();
115 HttpRequest
* proxy_req
= new HttpRequest(orig_request
->method
,
116 orig_request
->protocol
, url
);
118 proxy_req
->SetHost(_peer
->host
);
120 proxy_req
->port
= _peer
->http_port
;
122 proxy_req
->flags
= orig_request
->flags
;
124 proxy_req
->lastmod
= orig_request
->lastmod
;
126 proxy_req
->flags
.proxying
= 1;
128 HTTPMSGUNLOCK(request
);
130 request
= HTTPMSGLOCK(proxy_req
);
133 * This NEIGHBOR_PROXY_ONLY check probably shouldn't be here.
134 * We might end up getting the object from somewhere else if,
135 * for example, the request to this neighbor fails.
137 if (_peer
->options
.proxy_only
)
138 entry
->releaseRequest();
141 entry
->setNoDelay(_peer
->options
.no_delay
);
146 * register the handler to free HTTP state data when the FD closes
148 typedef CommCbMemFunT
<HttpStateData
, CommCloseCbParams
> Dialer
;
149 closeHandler
= JobCallback(9, 5,
150 Dialer
, this, HttpStateData::httpStateConnClosed
);
151 comm_add_close_handler(fd
, closeHandler
);
154 HttpStateData::~HttpStateData()
157 * don't forget that ~ServerStateData() gets called automatically
160 if (!readBuf
->isNull())
165 if (httpChunkDecoder
)
166 delete httpChunkDecoder
;
168 HTTPMSGUNLOCK(orig_request
);
170 debugs(11,5, HERE
<< "HttpStateData " << this << " destroyed; FD " << fd
);
174 HttpStateData::dataDescriptor() const
180 httpStateFree(int fd, void *data)
182 HttpStateData *httpState = static_cast<HttpStateData *>(data);
183 debugs(11, 5, "httpStateFree: FD " << fd << ", httpState=" << data);
188 HttpStateData::httpStateConnClosed(const CommCloseCbParams
¶ms
)
190 debugs(11, 5, "httpStateFree: FD " << params
.fd
<< ", httpState=" << params
.data
);
191 deleteThis("HttpStateData::httpStateConnClosed");
195 httpCachable(const HttpRequestMethod
& method
)
197 /* GET and HEAD are cachable. Others are not. */
199 // TODO: replase to HttpRequestMethod::isCachable() ?
200 if (method
!= METHOD_GET
&& method
!= METHOD_HEAD
)
208 HttpStateData::httpTimeout(const CommTimeoutCbParams
¶ms
)
210 debugs(11, 4, "httpTimeout: FD " << fd
<< ": '" << entry
->url() << "'" );
212 if (entry
->store_status
== STORE_PENDING
) {
213 fwd
->fail(errorCon(ERR_READ_TIMEOUT
, HTTP_GATEWAY_TIMEOUT
, fwd
->request
));
220 httpMaybeRemovePublic(StoreEntry
* e
, http_status status
)
226 if (!EBIT_TEST(e
->flags
, KEY_PRIVATE
))
233 case HTTP_NON_AUTHORITATIVE_INFORMATION
:
235 case HTTP_MULTIPLE_CHOICES
:
237 case HTTP_MOVED_PERMANENTLY
:
239 case HTTP_MOVED_TEMPORARILY
:
250 case HTTP_METHOD_NOT_ALLOWED
:
257 case HTTP_UNAUTHORIZED
:
267 * Any 2xx response should eject previously cached entities...
270 if (status
>= 200 && status
< 300)
278 if (!remove
&& !forbidden
)
283 if (e
->mem_obj
->request
)
284 pe
= storeGetPublicByRequest(e
->mem_obj
->request
);
286 pe
= storeGetPublic(e
->mem_obj
->url
, e
->mem_obj
->method
);
291 neighborsHtcpClear(e
, NULL
, e
->mem_obj
->request
, e
->mem_obj
->method
, HTCP_CLR_INVALIDATION
);
297 * Also remove any cached HEAD response in case the object has
300 if (e
->mem_obj
->request
)
301 pe
= storeGetPublicByRequestMethod(e
->mem_obj
->request
, METHOD_HEAD
);
303 pe
= storeGetPublic(e
->mem_obj
->url
, METHOD_HEAD
);
308 neighborsHtcpClear(e
, NULL
, e
->mem_obj
->request
, HttpRequestMethod(METHOD_HEAD
), HTCP_CLR_INVALIDATION
);
315 HttpStateData::processSurrogateControl(HttpReply
*reply
)
317 if (request
->flags
.accelerated
&& reply
->surrogate_control
) {
318 HttpHdrScTarget
*sctusable
= httpHdrScGetMergedTarget(reply
->surrogate_control
, Config
.Accel
.surrogate_id
);
321 if (EBIT_TEST(sctusable
->mask
, SC_NO_STORE
) ||
322 (Config
.onoff
.surrogate_is_remote
323 && EBIT_TEST(sctusable
->mask
, SC_NO_STORE_REMOTE
))) {
324 surrogateNoStore
= true;
325 entry
->makePrivate();
328 /* The HttpHeader logic cannot tell if the header it's parsing is a reply to an
329 * accelerated request or not...
330 * Still, this is an abstraction breach. - RC
332 if (sctusable
->max_age
!= -1) {
333 if (sctusable
->max_age
< sctusable
->max_stale
)
334 reply
->expires
= reply
->date
+ sctusable
->max_age
;
336 reply
->expires
= reply
->date
+ sctusable
->max_stale
;
338 /* And update the timestamps */
339 entry
->timestampsSet();
342 /* We ignore cache-control directives as per the Surrogate specification */
343 ignoreCacheControl
= true;
345 httpHdrScTargetDestroy(sctusable
);
351 HttpStateData::cacheableReply()
353 HttpReply
const *rep
= finalReply();
354 HttpHeader
const *hdr
= &rep
->header
;
355 const int cc_mask
= (rep
->cache_control
) ? rep
->cache_control
->mask
: 0;
357 #if USE_HTTP_VIOLATIONS
359 const refresh_t
*R
= NULL
;
361 /* This strange looking define first looks up the refresh pattern
362 * and then checks if the specified flag is set. The main purpose
363 * of this is to simplify the refresh pattern lookup and USE_HTTP_VIOLATIONS
366 #define REFRESH_OVERRIDE(flag) \
367 ((R = (R ? R : refreshLimits(entry->mem_obj->url))) , \
368 (R && R->flags.flag))
370 #define REFRESH_OVERRIDE(flag) 0
373 if (surrogateNoStore
)
376 // RFC 2616: do not cache replies to responses with no-store CC directive
377 if (request
&& request
->cache_control
&&
378 EBIT_TEST(request
->cache_control
->mask
, CC_NO_STORE
) &&
379 !REFRESH_OVERRIDE(ignore_no_store
))
382 if (!ignoreCacheControl
) {
383 if (EBIT_TEST(cc_mask
, CC_PRIVATE
)) {
384 if (!REFRESH_OVERRIDE(ignore_private
))
388 if (EBIT_TEST(cc_mask
, CC_NO_CACHE
)) {
389 if (!REFRESH_OVERRIDE(ignore_no_cache
))
393 if (EBIT_TEST(cc_mask
, CC_NO_STORE
)) {
394 if (!REFRESH_OVERRIDE(ignore_no_store
))
399 if (request
->flags
.auth
|| request
->flags
.auth_sent
) {
401 * Responses to requests with authorization may be cached
402 * only if a Cache-Control: public reply header is present.
403 * RFC 2068, sec 14.9.4
406 if (!EBIT_TEST(cc_mask
, CC_PUBLIC
)) {
407 if (!REFRESH_OVERRIDE(ignore_auth
))
412 /* Pragma: no-cache in _replies_ is not documented in HTTP,
413 * but servers like "Active Imaging Webcast/2.0" sure do use it */
414 if (hdr
->has(HDR_PRAGMA
)) {
415 String s
= hdr
->getList(HDR_PRAGMA
);
416 const int no_cache
= strListIsMember(&s
, "no-cache", ',');
420 if (!REFRESH_OVERRIDE(ignore_no_cache
))
426 * The "multipart/x-mixed-replace" content type is used for
427 * continuous push replies. These are generally dynamic and
428 * probably should not be cachable
430 if ((v
= hdr
->getStr(HDR_CONTENT_TYPE
)))
431 if (!strncasecmp(v
, "multipart/x-mixed-replace", 25))
434 switch (rep
->sline
.status
) {
435 /* Responses that are cacheable */
439 case HTTP_NON_AUTHORITATIVE_INFORMATION
:
441 case HTTP_MULTIPLE_CHOICES
:
443 case HTTP_MOVED_PERMANENTLY
:
447 * Don't cache objects that need to be refreshed on next request,
448 * unless we know how to refresh it.
451 if (!refreshIsCachable(entry
) && !REFRESH_OVERRIDE(store_stale
)) {
452 debugs(22, 3, "refreshIsCachable() returned non-cacheable..");
460 /* Responses that only are cacheable if the server says so */
462 case HTTP_MOVED_TEMPORARILY
:
463 case HTTP_TEMPORARY_REDIRECT
:
464 if (rep
->expires
> rep
->date
&& rep
->date
> 0)
472 /* Errors can be negatively cached */
474 case HTTP_NO_CONTENT
:
478 case HTTP_BAD_REQUEST
:
484 case HTTP_METHOD_NOT_ALLOWED
:
486 case HTTP_REQUEST_URI_TOO_LARGE
:
488 case HTTP_INTERNAL_SERVER_ERROR
:
490 case HTTP_NOT_IMPLEMENTED
:
492 case HTTP_BAD_GATEWAY
:
494 case HTTP_SERVICE_UNAVAILABLE
:
496 case HTTP_GATEWAY_TIMEOUT
:
502 /* Some responses can never be cached */
504 case HTTP_PARTIAL_CONTENT
: /* Not yet supported */
508 case HTTP_NOT_MODIFIED
:
510 case HTTP_UNAUTHORIZED
:
512 case HTTP_PROXY_AUTHENTICATION_REQUIRED
:
514 case HTTP_INVALID_HEADER
: /* Squid header parsing error */
516 case HTTP_HEADER_TOO_LARGE
:
518 case HTTP_PAYMENT_REQUIRED
:
519 case HTTP_NOT_ACCEPTABLE
:
520 case HTTP_REQUEST_TIMEOUT
:
522 case HTTP_LENGTH_REQUIRED
:
523 case HTTP_PRECONDITION_FAILED
:
524 case HTTP_REQUEST_ENTITY_TOO_LARGE
:
525 case HTTP_UNSUPPORTED_MEDIA_TYPE
:
526 case HTTP_UNPROCESSABLE_ENTITY
:
528 case HTTP_FAILED_DEPENDENCY
:
529 case HTTP_INSUFFICIENT_STORAGE
:
530 case HTTP_REQUESTED_RANGE_NOT_SATISFIABLE
:
531 case HTTP_EXPECTATION_FAILED
:
536 /* RFC 2616 section 6.1.1: an unrecognized response MUST NOT be cached. */
537 debugs (11, 3, HERE
<< "Unknown HTTP status code " << rep
->sline
.status
<< ". Not cacheable.");
549 * For Vary, store the relevant request headers as
550 * virtual headers in the reply
551 * Returns false if the variance cannot be stored
554 httpMakeVaryMark(HttpRequest
* request
, HttpReply
const * reply
)
557 const char *pos
= NULL
;
564 vary
= reply
->header
.getList(HDR_VARY
);
566 while (strListGetItem(&vary
, ',', &item
, &ilen
, &pos
)) {
567 char *name
= (char *)xmalloc(ilen
+ 1);
568 xstrncpy(name
, item
, ilen
+ 1);
571 if (strcmp(name
, "*") == 0) {
572 /* Can not handle "Vary: *" withtout ETag support */
578 strListAdd(&vstr
, name
, ',');
579 hdr
= request
->header
.getByName(name
);
581 value
= hdr
.termedBuf();
584 value
= rfc1738_escape_part(value
);
585 vstr
.append("=\"", 2);
587 vstr
.append("\"", 1);
594 #if X_ACCELERATOR_VARY
597 vary
= reply
->header
.getList(HDR_X_ACCELERATOR_VARY
);
599 while (strListGetItem(&vary
, ',', &item
, &ilen
, &pos
)) {
600 char *name
= (char *)xmalloc(ilen
+ 1);
601 xstrncpy(name
, item
, ilen
+ 1);
603 strListAdd(&vstr
, name
, ',');
604 hdr
= request
->header
.getByName(name
);
606 value
= hdr
.termedBuf();
609 value
= rfc1738_escape_part(value
);
610 vstr
.append("=\"", 2);
612 vstr
.append("\"", 1);
621 debugs(11, 3, "httpMakeVaryMark: " << vstr
);
622 return vstr
.termedBuf();
626 HttpStateData::keepaliveAccounting(HttpReply
*reply
)
630 _peer
->stats
.n_keepalives_sent
++;
632 if (reply
->keep_alive
) {
634 _peer
->stats
.n_keepalives_recv
++;
636 if (Config
.onoff
.detect_broken_server_pconns
637 && reply
->bodySize(request
->method
) == -1 && !flags
.chunked
) {
638 debugs(11, 1, "keepaliveAccounting: Impossible keep-alive header from '" << entry
->url() << "'" );
639 // debugs(11, 2, "GOT HTTP REPLY HDR:\n---------\n" << readBuf->content() << "\n----------" );
640 flags
.keepalive_broken
= 1;
646 HttpStateData::checkDateSkew(HttpReply
*reply
)
648 if (reply
->date
> -1 && !_peer
) {
649 int skew
= abs((int)(reply
->date
- squid_curtime
));
652 debugs(11, 3, "" << request
->GetHost() << "'s clock is skewed by " << skew
<< " seconds!");
657 * This creates the error page itself.. its likely
658 * that the forward ported reply header max size patch
659 * generates non http conformant error pages - in which
660 * case the errors where should be 'BAD_GATEWAY' etc
663 HttpStateData::processReplyHeader()
665 /** Creates a blank header. If this routine is made incremental, this will not do */
667 /* NP: all exit points to this function MUST call ctx_exit(ctx) */
668 Ctx ctx
= ctx_enter(entry
->mem_obj
->url
);
670 debugs(11, 3, "processReplyHeader: key '" << entry
->getMD5Text() << "'");
672 assert(!flags
.headers_parsed
);
674 if (!readBuf
->hasContent()) {
679 http_status error
= HTTP_STATUS_NONE
;
681 HttpReply
*newrep
= new HttpReply
;
682 const bool parsed
= newrep
->parse(readBuf
, eof
, &error
);
684 if (!parsed
&& readBuf
->contentSize() > 5 && strncmp(readBuf
->content(), "HTTP/", 5) != 0 && strncmp(readBuf
->content(), "ICY", 3) != 0) {
686 HttpReply
*tmprep
= new HttpReply
;
687 tmprep
->setHeaders(HTTP_OK
, "Gatewaying", NULL
, -1, -1, -1);
688 tmprep
->header
.putExt("X-Transformed-From", "HTTP/0.9");
690 newrep
->parse(mb
, eof
, &error
);
694 if (!parsed
&& error
> 0) { // unrecoverable parsing error
695 debugs(11, 3, "processReplyHeader: Non-HTTP-compliant header: '" << readBuf
->content() << "'");
696 flags
.headers_parsed
= 1;
697 newrep
->sline
.version
= HttpVersion(1,1);
698 newrep
->sline
.status
= error
;
699 HttpReply
*vrep
= setVirginReply(newrep
);
700 entry
->replaceHttpReply(vrep
);
705 if (!parsed
) { // need more data
713 debugs(11, 9, "GOT HTTP REPLY HDR:\n---------\n" << readBuf
->content() << "\n----------");
715 header_bytes_read
= headersEnd(readBuf
->content(), readBuf
->contentSize());
716 readBuf
->consume(header_bytes_read
);
719 newrep
->removeStaleWarnings();
721 if (newrep
->sline
.protocol
== AnyP::PROTO_HTTP
&& newrep
->sline
.status
>= 100 && newrep
->sline
.status
< 200) {
728 if (newrep
->sline
.protocol
== AnyP::PROTO_HTTP
&& newrep
->header
.chunked()) {
730 httpChunkDecoder
= new ChunkedCodingParser
;
733 if (!peerSupportsConnectionPinning())
734 orig_request
->flags
.connection_auth_disabled
= 1;
736 HttpReply
*vrep
= setVirginReply(newrep
);
737 flags
.headers_parsed
= 1;
739 keepaliveAccounting(vrep
);
743 processSurrogateControl (vrep
);
745 /** \todo IF the reply is a 1.0 reply, AND it has a Connection: Header
746 * Parse the header and remove all referenced headers
749 orig_request
->hier
.peer_reply_status
= newrep
->sline
.status
;
754 /// ignore or start forwarding the 1xx response (a.k.a., control message)
756 HttpStateData::handle1xx(HttpReply
*reply
)
758 HttpMsgPointerT
<HttpReply
> msg(reply
); // will destroy reply if unused
760 // one 1xx at a time: we must not be called while waiting for previous 1xx
761 Must(!flags
.handling1xx
);
762 flags
.handling1xx
= true;
764 if (!orig_request
->canHandle1xx()) {
765 debugs(11, 2, HERE
<< "ignoring client-unsupported 1xx");
770 #if USE_HTTP_VIOLATIONS
771 // check whether the 1xx response forwarding is allowed by squid.conf
772 if (Config
.accessList
.reply
) {
773 ACLFilledChecklist
ch(Config
.accessList
.reply
, originalRequest(), NULL
);
774 ch
.reply
= HTTPMSGLOCK(reply
);
775 if (!ch
.fastCheck()) { // TODO: support slow lookups?
776 debugs(11, 3, HERE
<< "ignoring denied 1xx");
781 #endif // USE_HTTP_VIOLATIONS
783 debugs(11, 2, HERE
<< "forwarding 1xx to client");
785 // the Sink will use this to call us back after writing 1xx to the client
786 typedef NullaryMemFunT
<HttpStateData
> CbDialer
;
787 const AsyncCall::Pointer cb
= JobCallback(11, 3, CbDialer
, this,
788 HttpStateData::proceedAfter1xx
);
789 CallJobHere1(11, 4, orig_request
->clientConnectionManager
, ConnStateData
,
790 ConnStateData::sendControlMsg
, HttpControlMsg(msg
, cb
));
791 // If the call is not fired, then the Sink is gone, and HttpStateData
792 // will terminate due to an aborted store entry or another similar error.
793 // If we get stuck, it is not handle1xx fault if we could get stuck
794 // for similar reasons without a 1xx response.
797 /// restores state and resumes processing after 1xx is ignored or forwarded
799 HttpStateData::proceedAfter1xx()
801 Must(flags
.handling1xx
);
803 debugs(11, 2, HERE
<< "consuming " << header_bytes_read
<<
804 " header and " << reply_bytes_read
<< " body bytes read after 1xx");
805 header_bytes_read
= 0;
806 reply_bytes_read
= 0;
808 CallJobHere(11, 3, this, HttpStateData
, HttpStateData::processReply
);
813 * returns true if the peer can support connection pinning
815 bool HttpStateData::peerSupportsConnectionPinning() const
817 const HttpReply
*rep
= entry
->mem_obj
->getReply();
818 const HttpHeader
*hdr
= &rep
->header
;
825 /*If this peer does not support connection pinning (authenticated
826 connections) return false
828 if (!_peer
->connection_auth
)
831 /*The peer supports connection pinning and the http reply status
832 is not unauthorized, so the related connection can be pinned
834 if (rep
->sline
.status
!= HTTP_UNAUTHORIZED
)
837 /*The server respond with HTTP_UNAUTHORIZED and the peer configured
838 with "connection-auth=on" we know that the peer supports pinned
841 if (_peer
->connection_auth
== 1)
844 /*At this point peer has configured with "connection-auth=auto"
845 parameter so we need some extra checks to decide if we are going
846 to allow pinned connections or not
849 /*if the peer configured with originserver just allow connection
850 pinning (squid 2.6 behaviour)
852 if (_peer
->options
.originserver
)
855 /*if the connections it is already pinned it is OK*/
856 if (request
->flags
.pinned
)
859 /*Allow pinned connections only if the Proxy-support header exists in
860 reply and has in its list the "Session-Based-Authentication"
861 which means that the peer supports connection pinning.
863 if (!hdr
->has(HDR_PROXY_SUPPORT
))
866 header
= hdr
->getStrOrList(HDR_PROXY_SUPPORT
);
867 /* XXX This ought to be done in a case-insensitive manner */
868 rc
= (strstr(header
.termedBuf(), "Session-Based-Authentication") != NULL
);
873 // Called when we parsed (and possibly adapted) the headers but
874 // had not starting storing (a.k.a., sending) the body yet.
876 HttpStateData::haveParsedReplyHeaders()
878 ServerStateData::haveParsedReplyHeaders();
880 Ctx ctx
= ctx_enter(entry
->mem_obj
->url
);
881 HttpReply
*rep
= finalReply();
883 if (rep
->sline
.status
== HTTP_PARTIAL_CONTENT
&&
885 currentOffset
= rep
->content_range
->spec
.offset
;
887 entry
->timestampsSet();
889 /* Check if object is cacheable or not based on reply code */
890 debugs(11, 3, "haveParsedReplyHeaders: HTTP CODE: " << rep
->sline
.status
);
892 if (neighbors_do_private_keys
)
893 httpMaybeRemovePublic(entry
, rep
->sline
.status
);
895 if (rep
->header
.has(HDR_VARY
)
896 #if X_ACCELERATOR_VARY
897 || rep
->header
.has(HDR_X_ACCELERATOR_VARY
)
900 const char *vary
= httpMakeVaryMark(orig_request
, rep
);
903 entry
->makePrivate();
904 if (!fwd
->reforwardableStatus(rep
->sline
.status
))
905 EBIT_CLR(entry
->flags
, ENTRY_FWD_HDR_WAIT
);
909 entry
->mem_obj
->vary_headers
= xstrdup(vary
);
913 * If its not a reply that we will re-forward, then
914 * allow the client to get it.
916 if (!fwd
->reforwardableStatus(rep
->sline
.status
))
917 EBIT_CLR(entry
->flags
, ENTRY_FWD_HDR_WAIT
);
919 switch (cacheableReply()) {
926 entry
->makePrivate();
931 #if USE_HTTP_VIOLATIONS
932 if (Config
.negativeTtl
> 0)
933 entry
->cacheNegatively();
936 entry
->makePrivate();
948 if (!ignoreCacheControl
&& rep
->cache_control
) {
949 if (EBIT_TEST(rep
->cache_control
->mask
, CC_PROXY_REVALIDATE
) ||
950 EBIT_TEST(rep
->cache_control
->mask
, CC_MUST_REVALIDATE
) ||
951 EBIT_TEST(rep
->cache_control
->mask
, CC_S_MAXAGE
))
952 EBIT_SET(entry
->flags
, ENTRY_REVALIDATE
);
956 headersLog(1, 0, request
->method
, rep
);
963 HttpStateData::ConnectionStatus
964 HttpStateData::statusIfComplete() const
966 const HttpReply
*rep
= virginReply();
968 * If the reply wants to close the connection, it takes precedence */
970 if (httpHeaderHasConnDir(&rep
->header
, "close"))
971 return COMPLETE_NONPERSISTENT_MSG
;
974 * If we didn't send a keep-alive request header, then this
975 * can not be a persistent connection.
977 if (!flags
.keepalive
)
978 return COMPLETE_NONPERSISTENT_MSG
;
981 * If we haven't sent the whole request then this can not be a persistent
984 if (!flags
.request_sent
) {
985 debugs(11, 2, "statusIfComplete: Request not yet fully sent \"" << RequestMethodStr(orig_request
->method
) << " " << entry
->url() << "\"" );
986 return COMPLETE_NONPERSISTENT_MSG
;
990 * What does the reply have to say about keep-alive?
994 * If the origin server (HTTP/1.0) does not send a keep-alive
995 * header, but keeps the connection open anyway, what happens?
996 * We'll return here and http.c waits for an EOF before changing
997 * store_status to STORE_OK. Combine this with ENTRY_FWD_HDR_WAIT
998 * and an error status code, and we might have to wait until
999 * the server times out the socket.
1001 if (!rep
->keep_alive
)
1002 return COMPLETE_NONPERSISTENT_MSG
;
1004 return COMPLETE_PERSISTENT_MSG
;
1007 HttpStateData::ConnectionStatus
1008 HttpStateData::persistentConnStatus() const
1010 debugs(11, 3, "persistentConnStatus: FD " << fd
<< " eof=" << eof
);
1011 if (eof
) // already reached EOF
1012 return COMPLETE_NONPERSISTENT_MSG
;
1014 /* If server fd is closing (but we have not been notified yet), stop Comm
1015 I/O to avoid assertions. TODO: Change Comm API to handle callers that
1016 want more I/O after async closing (usually initiated by others). */
1017 // XXX: add canReceive or s/canSend/canTalkToServer/
1019 return COMPLETE_NONPERSISTENT_MSG
;
1022 * In chunked response we do not know the content length but we are absolutely
1023 * sure about the end of response, so we are calling the statusIfComplete to
1024 * decide if we can be persistant
1026 if (lastChunk
&& flags
.chunked
)
1027 return statusIfComplete();
1029 const HttpReply
*vrep
= virginReply();
1030 debugs(11, 5, "persistentConnStatus: content_length=" << vrep
->content_length
);
1032 const int64_t clen
= vrep
->bodySize(request
->method
);
1034 debugs(11, 5, "persistentConnStatus: clen=" << clen
);
1036 /* If the body size is unknown we must wait for EOF */
1038 return INCOMPLETE_MSG
;
1041 * If the body size is known, we must wait until we've gotten all of it. */
1044 // if (entry->mem_obj->endOffset() < vrep->content_length + vrep->hdr_sz)
1045 const int64_t body_bytes_read
= reply_bytes_read
- header_bytes_read
;
1046 debugs(11,5, "persistentConnStatus: body_bytes_read=" <<
1047 body_bytes_read
<< " content_length=" << vrep
->content_length
);
1049 if (body_bytes_read
< vrep
->content_length
)
1050 return INCOMPLETE_MSG
;
1052 if (body_bytes_truncated
> 0) // already read more than needed
1053 return COMPLETE_NONPERSISTENT_MSG
; // disable pconns
1057 * If there is no message body or we got it all, we can be persistent */
1058 return statusIfComplete();
1062 * This is the callback after some data has been read from the network
1066 HttpStateData::ReadReplyWrapper(int fd, char *buf, size_t len, comm_err_t flag, int xerrno, void *data)
1068 HttpStateData *httpState = static_cast<HttpStateData *>(data);
1069 assert (fd == httpState->fd);
1070 // assert(buf == readBuf->content());
1071 PROF_start(HttpStateData_readReply);
1072 httpState->readReply(len, flag, xerrno);
1073 PROF_stop(HttpStateData_readReply);
1077 /* XXX this function is too long! */
1079 HttpStateData::readReply(const CommIoCbParams
&io
)
1085 assert(fd
== io
.fd
);
1087 flags
.do_next_read
= 0;
1089 debugs(11, 5, "httpReadReply: FD " << fd
<< ": len " << len
<< ".");
1091 // Bail out early on COMM_ERR_CLOSING - close handlers will tidy up for us
1092 if (io
.flag
== COMM_ERR_CLOSING
) {
1093 debugs(11, 3, "http socket closing");
1097 if (EBIT_TEST(entry
->flags
, ENTRY_ABORTED
)) {
1098 maybeReadVirginBody();
1102 // handle I/O errors
1103 if (io
.flag
!= COMM_OK
|| len
< 0) {
1104 debugs(11, 2, "httpReadReply: FD " << fd
<< ": read failure: " << xstrerror() << ".");
1106 if (ignoreErrno(io
.xerrno
)) {
1107 flags
.do_next_read
= 1;
1110 err
= errorCon(ERR_READ_ERROR
, HTTP_BAD_GATEWAY
, fwd
->request
);
1111 err
->xerrno
= io
.xerrno
;
1113 flags
.do_next_read
= 0;
1122 readBuf
->appended(len
);
1123 reply_bytes_read
+= len
;
1125 DelayId delayId
= entry
->mem_obj
->mostBytesAllowed();
1126 delayId
.bytesIn(len
);
1129 kb_incr(&statCounter
.server
.all
.kbytes_in
, len
);
1130 kb_incr(&statCounter
.server
.http
.kbytes_in
, len
);
1131 IOStats
.Http
.reads
++;
1133 for (clen
= len
- 1, bin
= 0; clen
; bin
++)
1136 IOStats
.Http
.read_hist
[bin
]++;
1138 // update peer response time stats (%<pt)
1139 const timeval
&sent
= orig_request
->hier
.peer_http_request_sent
;
1140 orig_request
->hier
.peer_response_time
=
1141 sent
.tv_sec
? tvSubMsec(sent
, current_time
) : -1;
1145 * Here the RFC says we should ignore whitespace between replies, but we can't as
1146 * doing so breaks HTTP/0.9 replies beginning with witespace, and in addition
1147 * the response splitting countermeasures is extremely likely to trigger on this,
1148 * not allowing connection reuse in the first place.
1151 if (!flags
.headers_parsed
&& len
> 0 && fd_table
[fd
].uses
> 1) {
1152 /* Skip whitespace between replies */
1154 while (len
> 0 && xisspace(*buf
))
1155 memmove(buf
, buf
+ 1, len
--);
1158 /* Continue to read... */
1159 /* Timeout NOT increased. This whitespace was from previous reply */
1160 flags
.do_next_read
= 1;
1161 maybeReadVirginBody();
1168 if (len
== 0) { // reached EOF?
1170 flags
.do_next_read
= 0;
1172 /* Bug 2879: Replies may terminate with \r\n then EOF instead of \r\n\r\n
1173 * Ensure here that we have at minimum two \r\n when EOF is seen.
1174 * TODO: Add eof parameter to headersEnd() and move this hack there.
1176 if (readBuf
->contentSize() && !flags
.headers_parsed
) {
1178 * Yes Henrik, there is a point to doing this. When we
1179 * called httpProcessReplyHeader() before, we didn't find
1180 * the end of headers, but now we are definately at EOF, so
1181 * we want to process the reply headers.
1183 /* Fake an "end-of-headers" to work around such broken servers */
1184 readBuf
->append("\r\n", 2);
1191 /// processes the already read and buffered response data, possibly after
1192 /// waiting for asynchronous 1xx control message processing
1194 HttpStateData::processReply()
1197 if (flags
.handling1xx
) { // we came back after handling a 1xx response
1198 debugs(11, 5, HERE
<< "done with 1xx handling");
1199 flags
.handling1xx
= false;
1200 Must(!flags
.headers_parsed
);
1203 if (!flags
.headers_parsed
) { // have not parsed headers yet?
1204 PROF_start(HttpStateData_processReplyHeader
);
1205 processReplyHeader();
1206 PROF_stop(HttpStateData_processReplyHeader
);
1208 if (!continueAfterParsingHeader()) // parsing error or need more data
1209 return; // TODO: send errors to ICAP
1211 adaptOrFinalizeReply();
1212 // adaptOrFinalizeReply() may abort or otherwise "close" the entry
1213 if (!entry
->isAccepting())
1217 // kick more reads if needed and/or process the response body, if any
1218 PROF_start(HttpStateData_processReplyBody
);
1219 processReplyBody(); // may call serverComplete()
1220 PROF_stop(HttpStateData_processReplyBody
);
1224 \retval true if we can continue with processing the body or doing ICAP.
1227 HttpStateData::continueAfterParsingHeader()
1229 if (flags
.handling1xx
) {
1230 debugs(11, 5, HERE
<< "wait for 1xx handling");
1231 Must(!flags
.headers_parsed
);
1235 if (!flags
.headers_parsed
&& !eof
) {
1236 debugs(11, 9, HERE
<< "needs more at " << readBuf
->contentSize());
1237 flags
.do_next_read
= 1;
1238 /** \retval false If we have not finished parsing the headers and may get more data.
1239 * Schedules more reads to retrieve the missing data.
1241 maybeReadVirginBody(); // schedules all kinds of reads; TODO: rename
1245 /** If we are done with parsing, check for errors */
1247 err_type error
= ERR_NONE
;
1249 if (flags
.headers_parsed
) { // parsed headers, possibly with errors
1250 // check for header parsing errors
1251 if (HttpReply
*vrep
= virginReply()) {
1252 const http_status s
= vrep
->sline
.status
;
1253 const HttpVersion
&v
= vrep
->sline
.version
;
1254 if (s
== HTTP_INVALID_HEADER
&& v
!= HttpVersion(0,9)) {
1255 debugs(11, DBG_IMPORTANT
, "WARNING: HTTP: Invalid Response: Bad header encountered from " << entry
->url() << " AKA " << orig_request
->GetHost() << orig_request
->urlpath
.termedBuf() );
1256 error
= ERR_INVALID_RESP
;
1257 } else if (s
== HTTP_HEADER_TOO_LARGE
) {
1258 fwd
->dontRetry(true);
1259 error
= ERR_TOO_BIG
;
1261 return true; // done parsing, got reply, and no error
1264 // parsed headers but got no reply
1265 debugs(11, DBG_IMPORTANT
, "WARNING: HTTP: Invalid Response: No reply at all for " << entry
->url() << " AKA " << orig_request
->GetHost() << orig_request
->urlpath
.termedBuf() );
1266 error
= ERR_INVALID_RESP
;
1270 if (readBuf
->hasContent()) {
1271 error
= ERR_INVALID_RESP
;
1272 debugs(11, DBG_IMPORTANT
, "WARNING: HTTP: Invalid Response: Headers did not parse at all for " << entry
->url() << " AKA " << orig_request
->GetHost() << orig_request
->urlpath
.termedBuf() );
1274 error
= ERR_ZERO_SIZE_OBJECT
;
1275 debugs(11, (orig_request
->flags
.accelerated
?DBG_IMPORTANT
:2), "WARNING: HTTP: Invalid Response: No object data received for " <<
1276 entry
->url() << " AKA " << orig_request
->GetHost() << orig_request
->urlpath
.termedBuf() );
1280 assert(error
!= ERR_NONE
);
1282 fwd
->fail(errorCon(error
, HTTP_BAD_GATEWAY
, fwd
->request
));
1283 flags
.do_next_read
= 0;
1285 return false; // quit on error
1288 /** truncate what we read if we read too much so that writeReplyBody()
1289 writes no more than what we should have read */
1291 HttpStateData::truncateVirginBody()
1293 assert(flags
.headers_parsed
);
1295 HttpReply
*vrep
= virginReply();
1297 if (!vrep
->expectingBody(request
->method
, clen
) || clen
< 0)
1298 return; // no body or a body of unknown size, including chunked
1300 const int64_t body_bytes_read
= reply_bytes_read
- header_bytes_read
;
1301 if (body_bytes_read
- body_bytes_truncated
<= clen
)
1302 return; // we did not read too much or already took care of the extras
1304 if (const int64_t extras
= body_bytes_read
- body_bytes_truncated
- clen
) {
1305 // server sent more that the advertised content length
1306 debugs(11,5, HERE
<< "body_bytes_read=" << body_bytes_read
<<
1307 " clen=" << clen
<< '/' << vrep
->content_length
<<
1308 " body_bytes_truncated=" << body_bytes_truncated
<< '+' << extras
);
1310 readBuf
->truncate(extras
);
1311 body_bytes_truncated
+= extras
;
1316 * Call this when there is data from the origin server
1317 * which should be sent to either StoreEntry, or to ICAP...
1320 HttpStateData::writeReplyBody()
1322 truncateVirginBody(); // if needed
1323 const char *data
= readBuf
->content();
1324 int len
= readBuf
->contentSize();
1325 addVirginReplyBody(data
, len
);
1326 readBuf
->consume(len
);
1330 HttpStateData::decodeAndWriteReplyBody()
1332 const char *data
= NULL
;
1334 bool wasThereAnException
= false;
1335 assert(flags
.chunked
);
1336 assert(httpChunkDecoder
);
1337 SQUID_ENTER_THROWING_CODE();
1340 const bool doneParsing
= httpChunkDecoder
->parse(readBuf
,&decodedData
);
1341 len
= decodedData
.contentSize();
1342 data
=decodedData
.content();
1343 addVirginReplyBody(data
, len
);
1346 flags
.do_next_read
= 0;
1348 SQUID_EXIT_THROWING_CODE(wasThereAnException
);
1349 return wasThereAnException
;
1353 * processReplyBody has two purposes:
1354 * 1 - take the reply body data, if any, and put it into either
1355 * the StoreEntry, or give it over to ICAP.
1356 * 2 - see if we made it to the end of the response (persistent
1357 * connections and such)
1360 HttpStateData::processReplyBody()
1362 AsyncCall::Pointer call
;
1363 Ip::Address client_addr
;
1364 bool ispinned
= false;
1366 if (!flags
.headers_parsed
) {
1367 flags
.do_next_read
= 1;
1368 maybeReadVirginBody();
1373 debugs(11,5, HERE
<< "adaptationAccessCheckPending=" << adaptationAccessCheckPending
);
1374 if (adaptationAccessCheckPending
)
1380 * At this point the reply headers have been parsed and consumed.
1381 * That means header content has been removed from readBuf and
1382 * it contains only body data.
1384 if (flags
.chunked
) {
1385 if (!decodeAndWriteReplyBody()) {
1386 flags
.do_next_read
= 0;
1393 if (EBIT_TEST(entry
->flags
, ENTRY_ABORTED
)) {
1395 * The above writeReplyBody() call could ABORT this entry,
1396 * in that case, the server FD should already be closed.
1397 * there's nothing for us to do.
1401 switch (persistentConnStatus()) {
1402 case INCOMPLETE_MSG
:
1403 debugs(11, 5, "processReplyBody: INCOMPLETE_MSG");
1404 /* Wait for more data or EOF condition */
1405 if (flags
.keepalive_broken
) {
1407 commSetTimeout(fd
, 10, call
);
1410 commSetTimeout(fd
, Config
.Timeout
.read
, call
);
1413 flags
.do_next_read
= 1;
1416 case COMPLETE_PERSISTENT_MSG
:
1417 debugs(11, 5, "processReplyBody: COMPLETE_PERSISTENT_MSG");
1418 /* yes we have to clear all these! */
1420 commSetTimeout(fd
, -1, call
);
1421 flags
.do_next_read
= 0;
1423 comm_remove_close_handler(fd
, closeHandler
);
1424 closeHandler
= NULL
;
1425 fwd
->unregister(fd
);
1427 if (orig_request
->flags
.spoof_client_ip
)
1428 client_addr
= orig_request
->client_addr
;
1431 if (request
->flags
.pinned
) {
1433 } else if (request
->flags
.connection_auth
&& request
->flags
.auth_sent
) {
1437 if (orig_request
->pinnedConnection() && ispinned
) {
1438 orig_request
->pinnedConnection()->pinConnection(fd
, orig_request
, _peer
,
1439 (request
->flags
.connection_auth
!= 0));
1441 fwd
->pconnPush(fd
, _peer
, request
, orig_request
->GetHost(), client_addr
);
1449 case COMPLETE_NONPERSISTENT_MSG
:
1450 debugs(11, 5, "processReplyBody: COMPLETE_NONPERSISTENT_MSG");
1455 maybeReadVirginBody();
1459 HttpStateData::maybeReadVirginBody()
1461 // we may need to grow the buffer if headers do not fit
1462 const int minRead
= flags
.headers_parsed
? 0 :1024;
1463 const int read_size
= replyBodySpace(*readBuf
, minRead
);
1465 debugs(11,9, HERE
<< (flags
.do_next_read
? "may" : "wont") <<
1466 " read up to " << read_size
<< " bytes from FD " << fd
);
1469 * why <2? Because delayAwareRead() won't actually read if
1470 * you ask it to read 1 byte. The delayed read request
1471 * just gets re-queued until the client side drains, then
1472 * the I/O thread hangs. Better to not register any read
1473 * handler until we get a notification from someone that
1474 * its okay to read again.
1479 if (flags
.do_next_read
) {
1480 flags
.do_next_read
= 0;
1481 typedef CommCbMemFunT
<HttpStateData
, CommIoCbParams
> Dialer
;
1482 entry
->delayAwareRead(fd
, readBuf
->space(read_size
), read_size
,
1483 JobCallback(11, 5, Dialer
, this, HttpStateData::readReply
));
1487 /// called after writing the very last request byte (body, last-chunk, etc)
1489 HttpStateData::wroteLast(const CommIoCbParams
&io
)
1491 debugs(11, 5, HERE
<< "FD " << fd
<< ": size " << io
.size
<< ": errflag " << io
.flag
<< ".");
1492 #if URL_CHECKSUM_DEBUG
1494 entry
->mem_obj
->checkUrlChecksum();
1498 fd_bytes(fd
, io
.size
, FD_WRITE
);
1499 kb_incr(&statCounter
.server
.all
.kbytes_out
, io
.size
);
1500 kb_incr(&statCounter
.server
.http
.kbytes_out
, io
.size
);
1503 if (io
.flag
== COMM_ERR_CLOSING
)
1508 err
= errorCon(ERR_WRITE_ERROR
, HTTP_BAD_GATEWAY
, fwd
->request
);
1509 err
->xerrno
= io
.xerrno
;
1518 /// successfully wrote the entire request (including body, last-chunk, etc.)
1520 HttpStateData::sendComplete()
1523 * Set the read timeout here because it hasn't been set yet.
1524 * We only set the read timeout after the request has been
1525 * fully written to the server-side. If we start the timeout
1526 * after connection establishment, then we are likely to hit
1527 * the timeout for POST/PUT requests that have very large
1530 typedef CommCbMemFunT
<HttpStateData
, CommTimeoutCbParams
> TimeoutDialer
;
1531 AsyncCall::Pointer timeoutCall
= JobCallback(11, 5,
1532 TimeoutDialer
, this, HttpStateData::httpTimeout
);
1534 commSetTimeout(fd
, Config
.Timeout
.read
, timeoutCall
);
1536 flags
.request_sent
= 1;
1538 orig_request
->hier
.peer_http_request_sent
= current_time
;
1541 // Close the HTTP server connection. Used by serverComplete().
1543 HttpStateData::closeServer()
1545 debugs(11,5, HERE
<< "closing HTTP server FD " << fd
<< " this " << this);
1548 fwd
->unregister(fd
);
1549 comm_remove_close_handler(fd
, closeHandler
);
1550 closeHandler
= NULL
;
1557 HttpStateData::doneWithServer() const
1564 * Fixup authentication request headers for special cases
1567 httpFixupAuthentication(HttpRequest
* request
, HttpRequest
* orig_request
, const HttpHeader
* hdr_in
, HttpHeader
* hdr_out
, http_state_flags flags
)
1569 http_hdr_type header
= flags
.originpeer
? HDR_AUTHORIZATION
: HDR_PROXY_AUTHORIZATION
;
1571 /* Nothing to do unless we are forwarding to a peer */
1572 if (!request
->flags
.proxying
)
1575 /* Needs to be explicitly enabled */
1576 if (!orig_request
->peer_login
)
1579 /* Maybe already dealt with? */
1580 if (hdr_out
->has(header
))
1583 /* Nothing to do here for PASSTHRU */
1584 if (strcmp(orig_request
->peer_login
, "PASSTHRU") == 0)
1587 /* PROXYPASS is a special case, single-signon to servers with the proxy password (basic only) */
1588 if (flags
.originpeer
&& strcmp(orig_request
->peer_login
, "PROXYPASS") == 0 && hdr_in
->has(HDR_PROXY_AUTHORIZATION
)) {
1589 const char *auth
= hdr_in
->getStr(HDR_PROXY_AUTHORIZATION
);
1591 if (auth
&& strncasecmp(auth
, "basic ", 6) == 0) {
1592 hdr_out
->putStr(header
, auth
);
1597 /* Special mode to pass the username to the upstream cache */
1598 if (*orig_request
->peer_login
== '*') {
1600 const char *username
= "-";
1602 if (orig_request
->extacl_user
.size())
1603 username
= orig_request
->extacl_user
.termedBuf();
1605 else if (orig_request
->auth_user_request
!= NULL
)
1606 username
= orig_request
->auth_user_request
->username();
1609 snprintf(loginbuf
, sizeof(loginbuf
), "%s%s", username
, orig_request
->peer_login
+ 1);
1611 httpHeaderPutStrf(hdr_out
, header
, "Basic %s",
1612 old_base64_encode(loginbuf
));
1616 /* external_acl provided credentials */
1617 if (orig_request
->extacl_user
.size() && orig_request
->extacl_passwd
.size() &&
1618 (strcmp(orig_request
->peer_login
, "PASS") == 0 ||
1619 strcmp(orig_request
->peer_login
, "PROXYPASS") == 0)) {
1621 snprintf(loginbuf
, sizeof(loginbuf
), SQUIDSTRINGPH
":" SQUIDSTRINGPH
,
1622 SQUIDSTRINGPRINT(orig_request
->extacl_user
),
1623 SQUIDSTRINGPRINT(orig_request
->extacl_passwd
));
1624 httpHeaderPutStrf(hdr_out
, header
, "Basic %s",
1625 old_base64_encode(loginbuf
));
1629 /* Kerberos login to peer */
1630 #if HAVE_AUTH_MODULE_NEGOTIATE && HAVE_KRB5 && HAVE_GSSAPI
1631 if (strncmp(orig_request
->peer_login
, "NEGOTIATE",strlen("NEGOTIATE")) == 0) {
1633 char *PrincipalName
=NULL
,*p
;
1634 if ((p
=strchr(orig_request
->peer_login
,':')) != NULL
) {
1637 Token
= peer_proxy_negotiate_auth(PrincipalName
,request
->peer_host
);
1639 httpHeaderPutStrf(hdr_out
, HDR_PROXY_AUTHORIZATION
, "Negotiate %s",Token
);
1643 #endif /* HAVE_KRB5 && HAVE_GSSAPI */
1645 httpHeaderPutStrf(hdr_out
, header
, "Basic %s",
1646 old_base64_encode(orig_request
->peer_login
));
1651 * build request headers and append them to a given MemBuf
1652 * used by buildRequestPrefix()
1653 * note: initialised the HttpHeader, the caller is responsible for Clean()-ing
1656 HttpStateData::httpBuildRequestHeader(HttpRequest
* request
,
1657 HttpRequest
* orig_request
,
1659 HttpHeader
* hdr_out
,
1660 const http_state_flags flags
)
1662 /* building buffer for complex strings */
1663 #define BBUF_SZ (MAX_URL+32)
1664 LOCAL_ARRAY(char, bbuf
, BBUF_SZ
);
1665 LOCAL_ARRAY(char, ntoabuf
, MAX_IPSTRLEN
);
1666 const HttpHeader
*hdr_in
= &orig_request
->header
;
1667 const HttpHeaderEntry
*e
= NULL
;
1668 HttpHeaderPos pos
= HttpHeaderInitPos
;
1669 assert (hdr_out
->owner
== hoRequest
);
1671 /* append our IMS header */
1672 if (request
->lastmod
> -1)
1673 hdr_out
->putTime(HDR_IF_MODIFIED_SINCE
, request
->lastmod
);
1675 bool we_do_ranges
= decideIfWeDoRanges (orig_request
);
1677 String
strConnection (hdr_in
->getList(HDR_CONNECTION
));
1679 while ((e
= hdr_in
->getEntry(&pos
)))
1680 copyOneHeaderFromClientsideRequestToUpstreamRequest(e
, strConnection
, request
, orig_request
, hdr_out
, we_do_ranges
, flags
);
1682 /* Abstraction break: We should interpret multipart/byterange responses
1683 * into offset-length data, and this works around our inability to do so.
1685 if (!we_do_ranges
&& orig_request
->multipartRangeRequest()) {
1686 /* don't cache the result */
1687 orig_request
->flags
.cachable
= 0;
1688 /* pretend it's not a range request */
1689 delete orig_request
->range
;
1690 orig_request
->range
= NULL
;
1691 orig_request
->flags
.range
= 0;
1695 if (Config
.onoff
.via
) {
1697 strVia
= hdr_in
->getList(HDR_VIA
);
1698 snprintf(bbuf
, BBUF_SZ
, "%d.%d %s",
1699 orig_request
->http_ver
.major
,
1700 orig_request
->http_ver
.minor
, ThisCache
);
1701 strListAdd(&strVia
, bbuf
, ',');
1702 hdr_out
->putStr(HDR_VIA
, strVia
.termedBuf());
1706 if (orig_request
->flags
.accelerated
) {
1707 /* Append Surrogate-Capabilities */
1708 String
strSurrogate(hdr_in
->getList(HDR_SURROGATE_CAPABILITY
));
1710 snprintf(bbuf
, BBUF_SZ
, "%s=\"Surrogate/1.0 ESI/1.0\"", Config
.Accel
.surrogate_id
);
1712 snprintf(bbuf
, BBUF_SZ
, "%s=\"Surrogate/1.0\"", Config
.Accel
.surrogate_id
);
1714 strListAdd(&strSurrogate
, bbuf
, ',');
1715 hdr_out
->putStr(HDR_SURROGATE_CAPABILITY
, strSurrogate
.termedBuf());
1718 /** \pre Handle X-Forwarded-For */
1719 if (strcmp(opt_forwarded_for
, "delete") != 0) {
1721 String strFwd
= hdr_in
->getList(HDR_X_FORWARDED_FOR
);
1723 if (strFwd
.size() > 65536/2) {
1724 // There is probably a forwarding loop with Via detection disabled.
1725 // If we do nothing, String will assert on overflow soon.
1726 // TODO: Terminate all transactions with huge XFF?
1729 static int warnedCount
= 0;
1730 if (warnedCount
++ < 100) {
1731 const char *url
= entry
? entry
->url() : urlCanonical(orig_request
);
1732 debugs(11, 1, "Warning: likely forwarding loop with " << url
);
1736 if (strcmp(opt_forwarded_for
, "on") == 0) {
1737 /** If set to ON - append client IP or 'unknown'. */
1738 if ( orig_request
->client_addr
.IsNoAddr() )
1739 strListAdd(&strFwd
, "unknown", ',');
1741 strListAdd(&strFwd
, orig_request
->client_addr
.NtoA(ntoabuf
, MAX_IPSTRLEN
), ',');
1742 } else if (strcmp(opt_forwarded_for
, "off") == 0) {
1743 /** If set to OFF - append 'unknown'. */
1744 strListAdd(&strFwd
, "unknown", ',');
1745 } else if (strcmp(opt_forwarded_for
, "transparent") == 0) {
1746 /** If set to TRANSPARENT - pass through unchanged. */
1747 } else if (strcmp(opt_forwarded_for
, "truncate") == 0) {
1748 /** If set to TRUNCATE - drop existing list and replace with client IP or 'unknown'. */
1749 if ( orig_request
->client_addr
.IsNoAddr() )
1752 strFwd
= orig_request
->client_addr
.NtoA(ntoabuf
, MAX_IPSTRLEN
);
1754 if (strFwd
.size() > 0)
1755 hdr_out
->putStr(HDR_X_FORWARDED_FOR
, strFwd
.termedBuf());
1757 /** If set to DELETE - do not copy through. */
1759 /* append Host if not there already */
1760 if (!hdr_out
->has(HDR_HOST
)) {
1761 if (orig_request
->peer_domain
) {
1762 hdr_out
->putStr(HDR_HOST
, orig_request
->peer_domain
);
1763 } else if (orig_request
->port
== urlDefaultPort(orig_request
->protocol
)) {
1764 /* use port# only if not default */
1765 hdr_out
->putStr(HDR_HOST
, orig_request
->GetHost());
1767 httpHeaderPutStrf(hdr_out
, HDR_HOST
, "%s:%d",
1768 orig_request
->GetHost(),
1769 (int) orig_request
->port
);
1773 /* append Authorization if known in URL, not in header and going direct */
1774 if (!hdr_out
->has(HDR_AUTHORIZATION
)) {
1775 if (!request
->flags
.proxying
&& *request
->login
) {
1776 httpHeaderPutStrf(hdr_out
, HDR_AUTHORIZATION
, "Basic %s",
1777 old_base64_encode(request
->login
));
1781 /* Fixup (Proxy-)Authorization special cases. Plain relaying dealt with above */
1782 httpFixupAuthentication(request
, orig_request
, hdr_in
, hdr_out
, flags
);
1784 /* append Cache-Control, add max-age if not there already */
1786 HttpHdrCc
*cc
= hdr_in
->getCc();
1789 cc
= httpHdrCcCreate();
1791 #if 0 /* see bug 2330 */
1792 /* Set no-cache if determined needed but not found */
1793 if (orig_request
->flags
.nocache
)
1794 EBIT_SET(cc
->mask
, CC_NO_CACHE
);
1797 /* Add max-age only without no-cache */
1798 if (!EBIT_TEST(cc
->mask
, CC_MAX_AGE
) && !EBIT_TEST(cc
->mask
, CC_NO_CACHE
)) {
1800 entry
? entry
->url() : urlCanonical(orig_request
);
1801 httpHdrCcSetMaxAge(cc
, getMaxAge(url
));
1803 if (request
->urlpath
.size())
1804 assert(strstr(url
, request
->urlpath
.termedBuf()));
1807 /* Enforce sibling relations */
1808 if (flags
.only_if_cached
)
1809 EBIT_SET(cc
->mask
, CC_ONLY_IF_CACHED
);
1813 httpHdrCcDestroy(cc
);
1816 /* maybe append Connection: keep-alive */
1817 if (flags
.keepalive
) {
1818 hdr_out
->putStr(HDR_CONNECTION
, "keep-alive");
1821 /* append Front-End-Https */
1822 if (flags
.front_end_https
) {
1823 if (flags
.front_end_https
== 1 || request
->protocol
== AnyP::PROTO_HTTPS
)
1824 hdr_out
->putStr(HDR_FRONT_END_HTTPS
, "On");
1827 if (flags
.chunked_request
) {
1828 // Do not just copy the original value so that if the client-side
1829 // starts decode other encodings, this code may remain valid.
1830 hdr_out
->putStr(HDR_TRANSFER_ENCODING
, "chunked");
1833 /* Now mangle the headers. */
1834 if (Config2
.onoff
.mangle_request_headers
)
1835 httpHdrMangleList(hdr_out
, request
, ROR_REQUEST
);
1837 strConnection
.clean();
1841 * Decides whether a particular header may be cloned from the received Clients request
1842 * to our outgoing fetch request.
1845 copyOneHeaderFromClientsideRequestToUpstreamRequest(const HttpHeaderEntry
*e
, const String strConnection
, HttpRequest
* request
, const HttpRequest
* orig_request
, HttpHeader
* hdr_out
, const int we_do_ranges
, const http_state_flags flags
)
1847 debugs(11, 5, "httpBuildRequestHeader: " << e
->name
<< ": " << e
->value
);
1851 /** \par RFC 2616 sect 13.5.1 - Hop-by-Hop headers which Squid should not pass on. */
1853 case HDR_PROXY_AUTHORIZATION
:
1854 /** \par Proxy-Authorization:
1855 * Only pass on proxy authentication to peers for which
1856 * authentication forwarding is explicitly enabled
1858 if (!flags
.originpeer
&& flags
.proxying
&& orig_request
->peer_login
&&
1859 (strcmp(orig_request
->peer_login
, "PASS") == 0 ||
1860 strcmp(orig_request
->peer_login
, "PROXYPASS") == 0 ||
1861 strcmp(orig_request
->peer_login
, "PASSTHRU") == 0)) {
1862 hdr_out
->addEntry(e
->clone());
1866 /** \par RFC 2616 sect 13.5.1 - Hop-by-Hop headers which Squid does not pass on. */
1868 case HDR_CONNECTION
: /** \par Connection: */
1869 case HDR_TE
: /** \par TE: */
1870 case HDR_KEEP_ALIVE
: /** \par Keep-Alive: */
1871 case HDR_PROXY_AUTHENTICATE
: /** \par Proxy-Authenticate: */
1872 case HDR_TRAILER
: /** \par Trailer: */
1873 case HDR_UPGRADE
: /** \par Upgrade: */
1874 case HDR_TRANSFER_ENCODING
: /** \par Transfer-Encoding: */
1878 /** \par OTHER headers I haven't bothered to track down yet. */
1880 case HDR_AUTHORIZATION
:
1881 /** \par WWW-Authorization:
1882 * Pass on WWW authentication */
1884 if (!flags
.originpeer
) {
1885 hdr_out
->addEntry(e
->clone());
1887 /** \note In accelerators, only forward authentication if enabled
1888 * (see also httpFixupAuthentication for special cases)
1890 if (orig_request
->peer_login
&&
1891 (strcmp(orig_request
->peer_login
, "PASS") == 0 ||
1892 strcmp(orig_request
->peer_login
, "PASSTHRU") == 0 ||
1893 strcmp(orig_request
->peer_login
, "PROXYPASS") == 0)) {
1894 hdr_out
->addEntry(e
->clone());
1902 * Normally Squid rewrites the Host: header.
1903 * However, there is one case when we don't: If the URL
1904 * went through our redirector and the admin configured
1905 * 'redir_rewrites_host' to be off.
1907 if (orig_request
->peer_domain
)
1908 hdr_out
->putStr(HDR_HOST
, orig_request
->peer_domain
);
1909 else if (request
->flags
.redirected
&& !Config
.onoff
.redir_rewrites_host
)
1910 hdr_out
->addEntry(e
->clone());
1912 /* use port# only if not default */
1914 if (orig_request
->port
== urlDefaultPort(orig_request
->protocol
)) {
1915 hdr_out
->putStr(HDR_HOST
, orig_request
->GetHost());
1917 httpHeaderPutStrf(hdr_out
, HDR_HOST
, "%s:%d",
1918 orig_request
->GetHost(),
1919 (int) orig_request
->port
);
1925 case HDR_IF_MODIFIED_SINCE
:
1926 /** \par If-Modified-Since:
1927 * append unless we added our own;
1928 * \note at most one client's ims header can pass through */
1930 if (!hdr_out
->has(HDR_IF_MODIFIED_SINCE
))
1931 hdr_out
->addEntry(e
->clone());
1935 case HDR_MAX_FORWARDS
:
1936 /** \par Max-Forwards:
1937 * pass only on TRACE or OPTIONS requests */
1938 if (orig_request
->method
== METHOD_TRACE
|| orig_request
->method
== METHOD_OPTIONS
) {
1939 const int64_t hops
= e
->getInt64();
1942 hdr_out
->putInt64(HDR_MAX_FORWARDS
, hops
- 1);
1949 * If Via is disabled then forward any received header as-is.
1950 * Otherwise leave for explicit updated addition later. */
1952 if (!Config
.onoff
.via
)
1953 hdr_out
->addEntry(e
->clone());
1961 case HDR_REQUEST_RANGE
:
1962 /** \par Range:, If-Range:, Request-Range:
1963 * Only pass if we accept ranges */
1965 hdr_out
->addEntry(e
->clone());
1969 case HDR_PROXY_CONNECTION
: // SHOULD ignore. But doing so breaks things.
1972 case HDR_CONTENT_LENGTH
:
1973 // pass through unless we chunk; also, keeping this away from default
1974 // prevents request smuggling via Connection: Content-Length tricks
1975 if (!flags
.chunked_request
)
1976 hdr_out
->addEntry(e
->clone());
1979 case HDR_X_FORWARDED_FOR
:
1981 case HDR_CACHE_CONTROL
:
1982 /** \par X-Forwarded-For:, Cache-Control:
1983 * handled specially by Squid, so leave off for now.
1984 * append these after the loop if needed */
1987 case HDR_FRONT_END_HTTPS
:
1988 /** \par Front-End-Https:
1989 * Pass thru only if peer is configured with front-end-https */
1990 if (!flags
.front_end_https
)
1991 hdr_out
->addEntry(e
->clone());
1997 * pass on all other header fields
1998 * which are NOT listed by the special Connection: header. */
2000 if (strConnection
.size()>0 && strListIsMember(&strConnection
, e
->name
.termedBuf(), ',')) {
2001 debugs(11, 2, "'" << e
->name
<< "' header cropped by Connection: definition");
2005 hdr_out
->addEntry(e
->clone());
2010 HttpStateData::decideIfWeDoRanges (HttpRequest
* orig_request
)
2013 /* decide if we want to do Ranges ourselves
2014 * and fetch the whole object now)
2015 * We want to handle Ranges ourselves iff
2016 * - we can actually parse client Range specs
2017 * - the specs are expected to be simple enough (e.g. no out-of-order ranges)
2018 * - reply will be cachable
2019 * (If the reply will be uncachable we have to throw it away after
2020 * serving this request, so it is better to forward ranges to
2021 * the server and fetch only the requested content)
2024 int64_t roffLimit
= orig_request
->getRangeOffsetLimit();
2026 if (NULL
== orig_request
->range
|| !orig_request
->flags
.cachable
2027 || orig_request
->range
->offsetLimitExceeded(roffLimit
) || orig_request
->flags
.connection_auth
)
2030 debugs(11, 8, "decideIfWeDoRanges: range specs: " <<
2031 orig_request
->range
<< ", cachable: " <<
2032 orig_request
->flags
.cachable
<< "; we_do_ranges: " << result
);
2037 /* build request prefix and append it to a given MemBuf;
2038 * return the length of the prefix */
2040 HttpStateData::buildRequestPrefix(HttpRequest
* aRequest
,
2041 HttpRequest
* original_request
,
2042 StoreEntry
* sentry
,
2045 const int offset
= mb
->size
;
2046 HttpVersion
httpver(1,1);
2047 mb
->Printf("%s %s HTTP/%d.%d\r\n",
2048 RequestMethodStr(aRequest
->method
),
2049 aRequest
->urlpath
.size() ? aRequest
->urlpath
.termedBuf() : "/",
2050 httpver
.major
,httpver
.minor
);
2051 /* build and pack headers */
2053 HttpHeader
hdr(hoRequest
);
2055 httpBuildRequestHeader(aRequest
, original_request
, sentry
, &hdr
, flags
);
2057 if (aRequest
->flags
.pinned
&& aRequest
->flags
.connection_auth
)
2058 aRequest
->flags
.auth_sent
= 1;
2059 else if (hdr
.has(HDR_AUTHORIZATION
))
2060 aRequest
->flags
.auth_sent
= 1;
2062 packerToMemInit(&p
, mb
);
2067 /* append header terminator */
2068 mb
->append(crlf
, 2);
2069 return mb
->size
- offset
;
2072 /* This will be called when connect completes. Write request. */
2074 HttpStateData::sendRequest()
2078 debugs(11, 5, "httpSendRequest: FD " << fd
<< ", request " << request
<< ", this " << this << ".");
2081 debugs(11,3, HERE
<< "cannot send request to closing FD " << fd
);
2082 assert(closeHandler
!= NULL
);
2086 typedef CommCbMemFunT
<HttpStateData
, CommTimeoutCbParams
> TimeoutDialer
;
2087 AsyncCall::Pointer timeoutCall
= JobCallback(11, 5,
2088 TimeoutDialer
, this, HttpStateData::httpTimeout
);
2089 commSetTimeout(fd
, Config
.Timeout
.lifetime
, timeoutCall
);
2090 flags
.do_next_read
= 1;
2091 maybeReadVirginBody();
2093 if (orig_request
->body_pipe
!= NULL
) {
2094 if (!startRequestBodyFlow()) // register to receive body data
2096 typedef CommCbMemFunT
<HttpStateData
, CommIoCbParams
> Dialer
;
2097 requestSender
= JobCallback(11,5,
2098 Dialer
, this, HttpStateData::sentRequestBody
);
2100 Must(!flags
.chunked_request
);
2101 // use chunked encoding if we do not know the length
2102 if (orig_request
->content_length
< 0)
2103 flags
.chunked_request
= 1;
2105 assert(!requestBodySource
);
2106 typedef CommCbMemFunT
<HttpStateData
, CommIoCbParams
> Dialer
;
2107 requestSender
= JobCallback(11,5,
2108 Dialer
, this, HttpStateData::wroteLast
);
2111 if (_peer
!= NULL
) {
2112 if (_peer
->options
.originserver
) {
2114 flags
.originpeer
= 1;
2117 flags
.originpeer
= 0;
2121 flags
.originpeer
= 0;
2125 * Is keep-alive okay for all request methods?
2127 if (orig_request
->flags
.must_keepalive
)
2128 flags
.keepalive
= 1;
2129 else if (!Config
.onoff
.server_pconns
)
2130 flags
.keepalive
= 0;
2131 else if (_peer
== NULL
)
2132 flags
.keepalive
= 1;
2133 else if (_peer
->stats
.n_keepalives_sent
< 10)
2134 flags
.keepalive
= 1;
2135 else if ((double) _peer
->stats
.n_keepalives_recv
/
2136 (double) _peer
->stats
.n_keepalives_sent
> 0.50)
2137 flags
.keepalive
= 1;
2140 if (neighborType(_peer
, request
) == PEER_SIBLING
&&
2141 !_peer
->options
.allow_miss
)
2142 flags
.only_if_cached
= 1;
2144 flags
.front_end_https
= _peer
->front_end_https
;
2148 request
->peer_host
=_peer
?_peer
->host
:NULL
;
2149 buildRequestPrefix(request
, orig_request
, entry
, &mb
);
2150 debugs(11, 6, "httpSendRequest: FD " << fd
<< ":\n" << mb
.buf
);
2151 Comm::Write(fd
, &mb
, requestSender
);
2157 HttpStateData::getMoreRequestBody(MemBuf
&buf
)
2159 // parent's implementation can handle the no-encoding case
2160 if (!flags
.chunked_request
)
2161 return ServerStateData::getMoreRequestBody(buf
);
2165 Must(requestBodySource
!= NULL
);
2166 if (!requestBodySource
->getMoreData(raw
))
2167 return false; // no request body bytes to chunk yet
2169 // optimization: pre-allocate buffer size that should be enough
2170 const mb_size_t rawDataSize
= raw
.contentSize();
2171 // we may need to send: hex-chunk-size CRLF raw-data CRLF last-chunk
2172 buf
.init(16 + 2 + rawDataSize
+ 2 + 5, raw
.max_capacity
);
2174 buf
.Printf("%x\r\n", static_cast<unsigned int>(rawDataSize
));
2175 buf
.append(raw
.content(), rawDataSize
);
2178 Must(rawDataSize
> 0); // we did not accidently created last-chunk above
2180 // Do not send last-chunk unless we successfully received everything
2181 if (receivedWholeRequestBody
) {
2182 Must(!flags
.sentLastChunk
);
2183 flags
.sentLastChunk
= true;
2184 buf
.append("0\r\n\r\n", 5);
2191 httpStart(FwdState
*fwd
)
2193 debugs(11, 3, "httpStart: \"" << RequestMethodStr(fwd
->request
->method
) << " " << fwd
->entry
->url() << "\"" );
2194 HttpStateData
*httpState
= new HttpStateData(fwd
);
2196 if (!httpState
->sendRequest()) {
2197 debugs(11, 3, "httpStart: aborted");
2202 statCounter
.server
.all
.requests
++;
2203 statCounter
.server
.http
.requests
++;
2206 * We used to set the read timeout here, but not any more.
2207 * Now its set in httpSendComplete() after the full request,
2208 * including request body, has been written to the server.
2212 /// if broken posts are enabled for the request, try to fix and return true
2214 HttpStateData::finishingBrokenPost()
2216 #if USE_HTTP_VIOLATIONS
2217 if (!Config
.accessList
.brokenPosts
) {
2218 debugs(11, 5, HERE
<< "No brokenPosts list");
2222 ACLFilledChecklist
ch(Config
.accessList
.brokenPosts
, originalRequest(), NULL
);
2223 if (!ch
.fastCheck()) {
2224 debugs(11, 5, HERE
<< "didn't match brokenPosts");
2229 debugs(11,2, HERE
<< "ignoring broken POST for closing FD " << fd
);
2230 assert(closeHandler
!= NULL
);
2231 return true; // prevent caller from proceeding as if nothing happened
2234 debugs(11, 2, "finishingBrokenPost: fixing broken POST");
2235 typedef CommCbMemFunT
<HttpStateData
, CommIoCbParams
> Dialer
;
2236 requestSender
= JobCallback(11,5,
2237 Dialer
, this, HttpStateData::wroteLast
);
2238 Comm::Write(fd
, "\r\n", 2, requestSender
, NULL
);
2242 #endif /* USE_HTTP_VIOLATIONS */
2245 /// if needed, write last-chunk to end the request body and return true
2247 HttpStateData::finishingChunkedRequest()
2249 if (flags
.sentLastChunk
) {
2250 debugs(11, 5, HERE
<< "already sent last-chunk");
2254 Must(receivedWholeRequestBody
); // or we should not be sending last-chunk
2255 flags
.sentLastChunk
= true;
2257 typedef CommCbMemFunT
<HttpStateData
, CommIoCbParams
> Dialer
;
2258 requestSender
= JobCallback(11,5,
2259 Dialer
, this, HttpStateData::wroteLast
);
2260 Comm::Write(fd
, "0\r\n\r\n", 5, requestSender
, NULL
);
2265 HttpStateData::doneSendingRequestBody()
2267 ServerStateData::doneSendingRequestBody();
2268 debugs(11,5, HERE
<< "doneSendingRequestBody: FD " << fd
);
2270 // do we need to write something after the last body byte?
2271 if (flags
.chunked_request
&& finishingChunkedRequest())
2273 if (!flags
.chunked_request
&& finishingBrokenPost())
2279 // more origin request body data is available
2281 HttpStateData::handleMoreRequestBodyAvailable()
2283 if (eof
|| fd
< 0) {
2284 // XXX: we should check this condition in other callbacks then!
2285 // TODO: Check whether this can actually happen: We should unsubscribe
2286 // as a body consumer when the above condition(s) are detected.
2287 debugs(11, 1, HERE
<< "Transaction aborted while reading HTTP body");
2291 assert(requestBodySource
!= NULL
);
2293 if (requestBodySource
->buf().hasContent()) {
2294 // XXX: why does not this trigger a debug message on every request?
2296 if (flags
.headers_parsed
&& !flags
.abuse_detected
) {
2297 flags
.abuse_detected
= 1;
2298 debugs(11, 1, "http handleMoreRequestBodyAvailable: Likely proxy abuse detected '" << orig_request
->client_addr
<< "' -> '" << entry
->url() << "'" );
2300 if (virginReply()->sline
.status
== HTTP_INVALID_HEADER
) {
2307 HttpStateData::handleMoreRequestBodyAvailable();
2310 // premature end of the request body
2312 HttpStateData::handleRequestBodyProducerAborted()
2314 ServerStateData::handleRequestBodyProducerAborted();
2315 if (entry
->isEmpty()) {
2316 debugs(11, 3, "request body aborted: FD " << fd
);
2318 // We usually get here when ICAP REQMOD aborts during body processing.
2319 // We might also get here if client-side aborts, but then our response
2320 // should not matter because either client-side will provide its own or
2321 // there will be no response at all (e.g., if the the client has left).
2322 err
= errorCon(ERR_ICAP_FAILURE
, HTTP_INTERNAL_SERVER_ERROR
, fwd
->request
);
2323 err
->xerrno
= ERR_DETAIL_SRV_REQMOD_REQ_BODY
;
2327 abortTransaction("request body producer aborted");
2330 // called when we wrote request headers(!) or a part of the body
2332 HttpStateData::sentRequestBody(const CommIoCbParams
&io
)
2335 kb_incr(&statCounter
.server
.http
.kbytes_out
, io
.size
);
2337 ServerStateData::sentRequestBody(io
);
2340 // Quickly abort the transaction
2341 // TODO: destruction should be sufficient as the destructor should cleanup,
2342 // including canceling close handlers
2344 HttpStateData::abortTransaction(const char *reason
)
2346 debugs(11,5, HERE
<< "aborting transaction for " << reason
<<
2347 "; FD " << fd
<< ", this " << this);
2354 fwd
->handleUnregisteredServerEnd();
2355 deleteThis("HttpStateData::abortTransaction");
2359 HttpStateData::originalRequest()
2361 return orig_request
;