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.
42 #include "acl/FilledChecklist.h"
44 #include "base/AsyncJobCalls.h"
45 #include "base/TextException.h"
46 #include "client_side.h"
47 #include "comm/Connection.h"
48 #include "comm/Write.h"
49 #include "err_detail_type.h"
50 #include "errorpage.h"
53 #include "HttpControlMsg.h"
55 #include "HttpHdrCc.h"
56 #include "HttpHdrContRange.h"
57 #include "HttpHdrSc.h"
58 #include "HttpHdrScTarget.h"
59 #include "HttpHeaderTools.h"
60 #include "HttpReply.h"
61 #include "HttpRequest.h"
62 #include "log/access_log.h"
64 #include "MemObject.h"
65 #include "neighbors.h"
66 #include "profiler/Profiler.h"
70 #include "SquidTime.h"
71 #include "StatCounters.h"
77 #include "auth/UserRequest.h"
80 #include "DelayPools.h"
83 #define SQUID_ENTER_THROWING_CODE() try {
84 #define SQUID_EXIT_THROWING_CODE(status) \
87 catch (const std::exception &e) { \
88 debugs (11, 1, "Exception error:" << e.what()); \
92 CBDATA_CLASS_INIT(HttpStateData
);
94 static const char *const crlf
= "\r\n";
96 static void httpMaybeRemovePublic(StoreEntry
*, http_status
);
97 static void copyOneHeaderFromClientsideRequestToUpstreamRequest(const HttpHeaderEntry
*e
, const String strConnection
, const HttpRequest
* request
,
98 HttpHeader
* hdr_out
, const int we_do_ranges
, const http_state_flags
);
99 //Declared in HttpHeaderTools.cc
100 void httpHdrAdd(HttpHeader
*heads
, HttpRequest
*request
, const AccessLogEntryPointer
&al
, HeaderWithAclList
&headers_add
);
102 HttpStateData::HttpStateData(FwdState
*theFwdState
) : AsyncJob("HttpStateData"), ServerStateData(theFwdState
),
103 lastChunk(0), header_bytes_read(0), reply_bytes_read(0),
104 body_bytes_truncated(0), httpChunkDecoder(NULL
)
106 debugs(11,5,HERE
<< "HttpStateData " << this << " created");
107 ignoreCacheControl
= false;
108 surrogateNoStore
= false;
109 serverConnection
= fwd
->serverConnection();
110 readBuf
= new MemBuf
;
111 readBuf
->init(16*1024, 256*1024);
113 // reset peer response time stats for %<pt
114 request
->hier
.peer_http_request_sent
.tv_sec
= 0;
115 request
->hier
.peer_http_request_sent
.tv_usec
= 0;
117 if (fwd
->serverConnection() != NULL
)
118 _peer
= cbdataReference(fwd
->serverConnection()->getPeer()); /* might be NULL */
121 request
->flags
.proxying
= 1;
123 * This NEIGHBOR_PROXY_ONLY check probably shouldn't be here.
124 * We might end up getting the object from somewhere else if,
125 * for example, the request to this neighbor fails.
127 if (_peer
->options
.proxy_only
)
128 entry
->releaseRequest();
131 entry
->setNoDelay(_peer
->options
.no_delay
);
136 * register the handler to free HTTP state data when the FD closes
138 typedef CommCbMemFunT
<HttpStateData
, CommCloseCbParams
> Dialer
;
139 closeHandler
= JobCallback(9, 5, Dialer
, this, HttpStateData::httpStateConnClosed
);
140 comm_add_close_handler(serverConnection
->fd
, closeHandler
);
143 HttpStateData::~HttpStateData()
146 * don't forget that ~ServerStateData() gets called automatically
149 if (!readBuf
->isNull())
154 if (httpChunkDecoder
)
155 delete httpChunkDecoder
;
157 cbdataReferenceDone(_peer
);
159 debugs(11,5, HERE
<< "HttpStateData " << this << " destroyed; " << serverConnection
);
162 const Comm::ConnectionPointer
&
163 HttpStateData::dataConnection() const
165 return serverConnection
;
169 HttpStateData::httpStateConnClosed(const CommCloseCbParams
¶ms
)
171 debugs(11, 5, "httpStateFree: FD " << params
.fd
<< ", httpState=" << params
.data
);
172 mustStop("HttpStateData::httpStateConnClosed");
176 httpCachable(const HttpRequestMethod
& method
)
178 /* GET and HEAD are cachable. Others are not. */
180 // TODO: replase to HttpRequestMethod::isCachable() ?
181 if (method
!= METHOD_GET
&& method
!= METHOD_HEAD
)
189 HttpStateData::httpTimeout(const CommTimeoutCbParams
¶ms
)
191 debugs(11, 4, HERE
<< serverConnection
<< ": '" << entry
->url() << "'" );
193 if (entry
->store_status
== STORE_PENDING
) {
194 fwd
->fail(new ErrorState(ERR_READ_TIMEOUT
, HTTP_GATEWAY_TIMEOUT
, fwd
->request
));
197 serverConnection
->close();
201 httpMaybeRemovePublic(StoreEntry
* e
, http_status status
)
207 if (!EBIT_TEST(e
->flags
, KEY_PRIVATE
))
214 case HTTP_NON_AUTHORITATIVE_INFORMATION
:
216 case HTTP_MULTIPLE_CHOICES
:
218 case HTTP_MOVED_PERMANENTLY
:
220 case HTTP_MOVED_TEMPORARILY
:
231 case HTTP_METHOD_NOT_ALLOWED
:
238 case HTTP_UNAUTHORIZED
:
248 * Any 2xx response should eject previously cached entities...
251 if (status
>= 200 && status
< 300)
259 if (!remove
&& !forbidden
)
264 if (e
->mem_obj
->request
)
265 pe
= storeGetPublicByRequest(e
->mem_obj
->request
);
267 pe
= storeGetPublic(e
->mem_obj
->url
, e
->mem_obj
->method
);
272 neighborsHtcpClear(e
, NULL
, e
->mem_obj
->request
, e
->mem_obj
->method
, HTCP_CLR_INVALIDATION
);
278 * Also remove any cached HEAD response in case the object has
281 if (e
->mem_obj
->request
)
282 pe
= storeGetPublicByRequestMethod(e
->mem_obj
->request
, METHOD_HEAD
);
284 pe
= storeGetPublic(e
->mem_obj
->url
, METHOD_HEAD
);
289 neighborsHtcpClear(e
, NULL
, e
->mem_obj
->request
, HttpRequestMethod(METHOD_HEAD
), HTCP_CLR_INVALIDATION
);
296 HttpStateData::processSurrogateControl(HttpReply
*reply
)
298 if (request
->flags
.accelerated
&& reply
->surrogate_control
) {
299 HttpHdrScTarget
*sctusable
= reply
->surrogate_control
->getMergedTarget(Config
.Accel
.surrogate_id
);
302 if (sctusable
->noStore() ||
303 (Config
.onoff
.surrogate_is_remote
304 && sctusable
->noStoreRemote())) {
305 surrogateNoStore
= true;
306 entry
->makePrivate();
309 /* The HttpHeader logic cannot tell if the header it's parsing is a reply to an
310 * accelerated request or not...
311 * Still, this is an abstraction breach. - RC
313 if (sctusable
->hasMaxAge()) {
314 if (sctusable
->maxAge() < sctusable
->maxStale())
315 reply
->expires
= reply
->date
+ sctusable
->maxAge();
317 reply
->expires
= reply
->date
+ sctusable
->maxStale();
319 /* And update the timestamps */
320 entry
->timestampsSet();
323 /* We ignore cache-control directives as per the Surrogate specification */
324 ignoreCacheControl
= true;
332 HttpStateData::cacheableReply()
334 HttpReply
const *rep
= finalReply();
335 HttpHeader
const *hdr
= &rep
->header
;
337 #if USE_HTTP_VIOLATIONS
339 const refresh_t
*R
= NULL
;
341 /* This strange looking define first looks up the refresh pattern
342 * and then checks if the specified flag is set. The main purpose
343 * of this is to simplify the refresh pattern lookup and USE_HTTP_VIOLATIONS
346 #define REFRESH_OVERRIDE(flag) \
347 ((R = (R ? R : refreshLimits(entry->mem_obj->url))) , \
348 (R && R->flags.flag))
350 #define REFRESH_OVERRIDE(flag) 0
353 if (surrogateNoStore
)
356 // RFC 2616: do not cache replies to responses with no-store CC directive
357 if (request
&& request
->cache_control
&&
358 request
->cache_control
->noStore() &&
359 !REFRESH_OVERRIDE(ignore_no_store
))
362 if (!ignoreCacheControl
&& request
->cache_control
!= NULL
) {
363 const HttpHdrCc
* cc
=request
->cache_control
;
365 if (!REFRESH_OVERRIDE(ignore_private
))
370 if (!REFRESH_OVERRIDE(ignore_no_cache
))
375 if (!REFRESH_OVERRIDE(ignore_no_store
))
380 if (request
->flags
.auth
|| request
->flags
.auth_sent
) {
382 * Responses to requests with authorization may be cached
383 * only if a Cache-Control: public reply header is present.
384 * RFC 2068, sec 14.9.4
387 if (!request
->cache_control
|| !request
->cache_control
->Public()) {
388 if (!REFRESH_OVERRIDE(ignore_auth
))
393 /* Pragma: no-cache in _replies_ is not documented in HTTP,
394 * but servers like "Active Imaging Webcast/2.0" sure do use it */
395 if (hdr
->has(HDR_PRAGMA
)) {
396 String s
= hdr
->getList(HDR_PRAGMA
);
397 const int no_cache
= strListIsMember(&s
, "no-cache", ',');
401 if (!REFRESH_OVERRIDE(ignore_no_cache
))
407 * The "multipart/x-mixed-replace" content type is used for
408 * continuous push replies. These are generally dynamic and
409 * probably should not be cachable
411 if ((v
= hdr
->getStr(HDR_CONTENT_TYPE
)))
412 if (!strncasecmp(v
, "multipart/x-mixed-replace", 25))
415 switch (rep
->sline
.status
) {
416 /* Responses that are cacheable */
420 case HTTP_NON_AUTHORITATIVE_INFORMATION
:
422 case HTTP_MULTIPLE_CHOICES
:
424 case HTTP_MOVED_PERMANENTLY
:
425 case HTTP_PERMANENT_REDIRECT
:
429 * Don't cache objects that need to be refreshed on next request,
430 * unless we know how to refresh it.
433 if (!refreshIsCachable(entry
) && !REFRESH_OVERRIDE(store_stale
)) {
434 debugs(22, 3, "refreshIsCachable() returned non-cacheable..");
442 /* Responses that only are cacheable if the server says so */
444 case HTTP_MOVED_TEMPORARILY
:
445 case HTTP_TEMPORARY_REDIRECT
:
446 if (rep
->expires
> rep
->date
&& rep
->date
> 0)
454 /* Errors can be negatively cached */
456 case HTTP_NO_CONTENT
:
460 case HTTP_BAD_REQUEST
:
466 case HTTP_METHOD_NOT_ALLOWED
:
468 case HTTP_REQUEST_URI_TOO_LARGE
:
470 case HTTP_INTERNAL_SERVER_ERROR
:
472 case HTTP_NOT_IMPLEMENTED
:
474 case HTTP_BAD_GATEWAY
:
476 case HTTP_SERVICE_UNAVAILABLE
:
478 case HTTP_GATEWAY_TIMEOUT
:
484 /* Some responses can never be cached */
486 case HTTP_PARTIAL_CONTENT
: /* Not yet supported */
490 case HTTP_NOT_MODIFIED
:
492 case HTTP_UNAUTHORIZED
:
494 case HTTP_PROXY_AUTHENTICATION_REQUIRED
:
496 case HTTP_INVALID_HEADER
: /* Squid header parsing error */
498 case HTTP_HEADER_TOO_LARGE
:
500 case HTTP_PAYMENT_REQUIRED
:
501 case HTTP_NOT_ACCEPTABLE
:
502 case HTTP_REQUEST_TIMEOUT
:
504 case HTTP_LENGTH_REQUIRED
:
505 case HTTP_PRECONDITION_FAILED
:
506 case HTTP_REQUEST_ENTITY_TOO_LARGE
:
507 case HTTP_UNSUPPORTED_MEDIA_TYPE
:
508 case HTTP_UNPROCESSABLE_ENTITY
:
510 case HTTP_FAILED_DEPENDENCY
:
511 case HTTP_INSUFFICIENT_STORAGE
:
512 case HTTP_REQUESTED_RANGE_NOT_SATISFIABLE
:
513 case HTTP_EXPECTATION_FAILED
:
518 /* RFC 2616 section 6.1.1: an unrecognized response MUST NOT be cached. */
519 debugs (11, 3, HERE
<< "Unknown HTTP status code " << rep
->sline
.status
<< ". Not cacheable.");
531 * For Vary, store the relevant request headers as
532 * virtual headers in the reply
533 * Returns false if the variance cannot be stored
536 httpMakeVaryMark(HttpRequest
* request
, HttpReply
const * reply
)
539 const char *pos
= NULL
;
546 vary
= reply
->header
.getList(HDR_VARY
);
548 while (strListGetItem(&vary
, ',', &item
, &ilen
, &pos
)) {
549 char *name
= (char *)xmalloc(ilen
+ 1);
550 xstrncpy(name
, item
, ilen
+ 1);
553 if (strcmp(name
, "*") == 0) {
554 /* Can not handle "Vary: *" withtout ETag support */
560 strListAdd(&vstr
, name
, ',');
561 hdr
= request
->header
.getByName(name
);
563 value
= hdr
.termedBuf();
566 value
= rfc1738_escape_part(value
);
567 vstr
.append("=\"", 2);
569 vstr
.append("\"", 1);
576 #if X_ACCELERATOR_VARY
579 vary
= reply
->header
.getList(HDR_X_ACCELERATOR_VARY
);
581 while (strListGetItem(&vary
, ',', &item
, &ilen
, &pos
)) {
582 char *name
= (char *)xmalloc(ilen
+ 1);
583 xstrncpy(name
, item
, ilen
+ 1);
585 strListAdd(&vstr
, name
, ',');
586 hdr
= request
->header
.getByName(name
);
588 value
= hdr
.termedBuf();
591 value
= rfc1738_escape_part(value
);
592 vstr
.append("=\"", 2);
594 vstr
.append("\"", 1);
603 debugs(11, 3, "httpMakeVaryMark: " << vstr
);
604 return vstr
.termedBuf();
608 HttpStateData::keepaliveAccounting(HttpReply
*reply
)
612 ++ _peer
->stats
.n_keepalives_sent
;
614 if (reply
->keep_alive
) {
616 ++ _peer
->stats
.n_keepalives_recv
;
618 if (Config
.onoff
.detect_broken_server_pconns
619 && reply
->bodySize(request
->method
) == -1 && !flags
.chunked
) {
620 debugs(11, DBG_IMPORTANT
, "keepaliveAccounting: Impossible keep-alive header from '" << entry
->url() << "'" );
621 // debugs(11, 2, "GOT HTTP REPLY HDR:\n---------\n" << readBuf->content() << "\n----------" );
622 flags
.keepalive_broken
= 1;
628 HttpStateData::checkDateSkew(HttpReply
*reply
)
630 if (reply
->date
> -1 && !_peer
) {
631 int skew
= abs((int)(reply
->date
- squid_curtime
));
634 debugs(11, 3, "" << request
->GetHost() << "'s clock is skewed by " << skew
<< " seconds!");
639 * This creates the error page itself.. its likely
640 * that the forward ported reply header max size patch
641 * generates non http conformant error pages - in which
642 * case the errors where should be 'BAD_GATEWAY' etc
645 HttpStateData::processReplyHeader()
647 /** Creates a blank header. If this routine is made incremental, this will not do */
649 /* NP: all exit points to this function MUST call ctx_exit(ctx) */
650 Ctx ctx
= ctx_enter(entry
->mem_obj
->url
);
652 debugs(11, 3, "processReplyHeader: key '" << entry
->getMD5Text() << "'");
654 assert(!flags
.headers_parsed
);
656 if (!readBuf
->hasContent()) {
661 http_status error
= HTTP_STATUS_NONE
;
663 HttpReply
*newrep
= new HttpReply
;
664 const bool parsed
= newrep
->parse(readBuf
, eof
, &error
);
666 if (!parsed
&& readBuf
->contentSize() > 5 && strncmp(readBuf
->content(), "HTTP/", 5) != 0 && strncmp(readBuf
->content(), "ICY", 3) != 0) {
668 HttpReply
*tmprep
= new HttpReply
;
669 tmprep
->setHeaders(HTTP_OK
, "Gatewaying", NULL
, -1, -1, -1);
670 tmprep
->header
.putExt("X-Transformed-From", "HTTP/0.9");
672 newrep
->parse(mb
, eof
, &error
);
676 if (!parsed
&& error
> 0) { // unrecoverable parsing error
677 debugs(11, 3, "processReplyHeader: Non-HTTP-compliant header: '" << readBuf
->content() << "'");
678 flags
.headers_parsed
= 1;
679 newrep
->sline
.version
= HttpVersion(1,1);
680 newrep
->sline
.status
= error
;
681 HttpReply
*vrep
= setVirginReply(newrep
);
682 entry
->replaceHttpReply(vrep
);
687 if (!parsed
) { // need more data
695 debugs(11, 2, "HTTP Server " << serverConnection
);
696 debugs(11, 2, "HTTP Server REPLY:\n---------\n" << readBuf
->content() << "\n----------");
698 header_bytes_read
= headersEnd(readBuf
->content(), readBuf
->contentSize());
699 readBuf
->consume(header_bytes_read
);
702 newrep
->removeStaleWarnings();
704 if (newrep
->sline
.protocol
== AnyP::PROTO_HTTP
&& newrep
->sline
.status
>= 100 && newrep
->sline
.status
< 200) {
711 if (newrep
->sline
.protocol
== AnyP::PROTO_HTTP
&& newrep
->header
.chunked()) {
713 httpChunkDecoder
= new ChunkedCodingParser
;
716 if (!peerSupportsConnectionPinning())
717 request
->flags
.connection_auth_disabled
= 1;
719 HttpReply
*vrep
= setVirginReply(newrep
);
720 flags
.headers_parsed
= 1;
722 keepaliveAccounting(vrep
);
726 processSurrogateControl (vrep
);
728 /** \todo IF the reply is a 1.0 reply, AND it has a Connection: Header
729 * Parse the header and remove all referenced headers
732 request
->hier
.peer_reply_status
= newrep
->sline
.status
;
737 /// ignore or start forwarding the 1xx response (a.k.a., control message)
739 HttpStateData::handle1xx(HttpReply
*reply
)
741 HttpMsgPointerT
<HttpReply
> msg(reply
); // will destroy reply if unused
743 // one 1xx at a time: we must not be called while waiting for previous 1xx
744 Must(!flags
.handling1xx
);
745 flags
.handling1xx
= true;
747 if (!request
->canHandle1xx()) {
748 debugs(11, 2, HERE
<< "ignoring client-unsupported 1xx");
753 #if USE_HTTP_VIOLATIONS
754 // check whether the 1xx response forwarding is allowed by squid.conf
755 if (Config
.accessList
.reply
) {
756 ACLFilledChecklist
ch(Config
.accessList
.reply
, originalRequest(), NULL
);
757 ch
.reply
= HTTPMSGLOCK(reply
);
758 if (ch
.fastCheck() != ACCESS_ALLOWED
) { // TODO: support slow lookups?
759 debugs(11, 3, HERE
<< "ignoring denied 1xx");
764 #endif // USE_HTTP_VIOLATIONS
766 debugs(11, 2, HERE
<< "forwarding 1xx to client");
768 // the Sink will use this to call us back after writing 1xx to the client
769 typedef NullaryMemFunT
<HttpStateData
> CbDialer
;
770 const AsyncCall::Pointer cb
= JobCallback(11, 3, CbDialer
, this,
771 HttpStateData::proceedAfter1xx
);
772 CallJobHere1(11, 4, request
->clientConnectionManager
, ConnStateData
,
773 ConnStateData::sendControlMsg
, HttpControlMsg(msg
, cb
));
774 // If the call is not fired, then the Sink is gone, and HttpStateData
775 // will terminate due to an aborted store entry or another similar error.
776 // If we get stuck, it is not handle1xx fault if we could get stuck
777 // for similar reasons without a 1xx response.
780 /// restores state and resumes processing after 1xx is ignored or forwarded
782 HttpStateData::proceedAfter1xx()
784 Must(flags
.handling1xx
);
786 debugs(11, 2, HERE
<< "consuming " << header_bytes_read
<<
787 " header and " << reply_bytes_read
<< " body bytes read after 1xx");
788 header_bytes_read
= 0;
789 reply_bytes_read
= 0;
791 CallJobHere(11, 3, this, HttpStateData
, HttpStateData::processReply
);
795 * returns true if the peer can support connection pinning
797 bool HttpStateData::peerSupportsConnectionPinning() const
799 const HttpReply
*rep
= entry
->mem_obj
->getReply();
800 const HttpHeader
*hdr
= &rep
->header
;
807 /*If this peer does not support connection pinning (authenticated
808 connections) return false
810 if (!_peer
->connection_auth
)
813 /*The peer supports connection pinning and the http reply status
814 is not unauthorized, so the related connection can be pinned
816 if (rep
->sline
.status
!= HTTP_UNAUTHORIZED
)
819 /*The server respond with HTTP_UNAUTHORIZED and the peer configured
820 with "connection-auth=on" we know that the peer supports pinned
823 if (_peer
->connection_auth
== 1)
826 /*At this point peer has configured with "connection-auth=auto"
827 parameter so we need some extra checks to decide if we are going
828 to allow pinned connections or not
831 /*if the peer configured with originserver just allow connection
832 pinning (squid 2.6 behaviour)
834 if (_peer
->options
.originserver
)
837 /*if the connections it is already pinned it is OK*/
838 if (request
->flags
.pinned
)
841 /*Allow pinned connections only if the Proxy-support header exists in
842 reply and has in its list the "Session-Based-Authentication"
843 which means that the peer supports connection pinning.
845 if (!hdr
->has(HDR_PROXY_SUPPORT
))
848 header
= hdr
->getStrOrList(HDR_PROXY_SUPPORT
);
849 /* XXX This ought to be done in a case-insensitive manner */
850 rc
= (strstr(header
.termedBuf(), "Session-Based-Authentication") != NULL
);
855 // Called when we parsed (and possibly adapted) the headers but
856 // had not starting storing (a.k.a., sending) the body yet.
858 HttpStateData::haveParsedReplyHeaders()
860 ServerStateData::haveParsedReplyHeaders();
862 Ctx ctx
= ctx_enter(entry
->mem_obj
->url
);
863 HttpReply
*rep
= finalReply();
865 if (rep
->sline
.status
== HTTP_PARTIAL_CONTENT
&&
867 currentOffset
= rep
->content_range
->spec
.offset
;
869 entry
->timestampsSet();
871 /* Check if object is cacheable or not based on reply code */
872 debugs(11, 3, "haveParsedReplyHeaders: HTTP CODE: " << rep
->sline
.status
);
874 if (neighbors_do_private_keys
)
875 httpMaybeRemovePublic(entry
, rep
->sline
.status
);
877 if (rep
->header
.has(HDR_VARY
)
878 #if X_ACCELERATOR_VARY
879 || rep
->header
.has(HDR_X_ACCELERATOR_VARY
)
882 const char *vary
= httpMakeVaryMark(request
, rep
);
885 entry
->makePrivate();
886 if (!fwd
->reforwardableStatus(rep
->sline
.status
))
887 EBIT_CLR(entry
->flags
, ENTRY_FWD_HDR_WAIT
);
891 entry
->mem_obj
->vary_headers
= xstrdup(vary
);
895 * If its not a reply that we will re-forward, then
896 * allow the client to get it.
898 if (!fwd
->reforwardableStatus(rep
->sline
.status
))
899 EBIT_CLR(entry
->flags
, ENTRY_FWD_HDR_WAIT
);
901 switch (cacheableReply()) {
908 entry
->makePrivate();
913 #if USE_HTTP_VIOLATIONS
914 if (Config
.negativeTtl
> 0)
915 entry
->cacheNegatively();
918 entry
->makePrivate();
930 if (!ignoreCacheControl
&& rep
->cache_control
) {
931 if (rep
->cache_control
->proxyRevalidate() ||
932 rep
->cache_control
->mustRevalidate() ||
933 rep
->cache_control
->hasSMaxAge()
935 EBIT_SET(entry
->flags
, ENTRY_REVALIDATE
);
939 headersLog(1, 0, request
->method
, rep
);
946 HttpStateData::ConnectionStatus
947 HttpStateData::statusIfComplete() const
949 const HttpReply
*rep
= virginReply();
951 * If the reply wants to close the connection, it takes precedence */
953 if (httpHeaderHasConnDir(&rep
->header
, "close"))
954 return COMPLETE_NONPERSISTENT_MSG
;
957 * If we didn't send a keep-alive request header, then this
958 * can not be a persistent connection.
960 if (!flags
.keepalive
)
961 return COMPLETE_NONPERSISTENT_MSG
;
964 * If we haven't sent the whole request then this can not be a persistent
967 if (!flags
.request_sent
) {
968 debugs(11, 2, "statusIfComplete: Request not yet fully sent \"" << RequestMethodStr(request
->method
) << " " << entry
->url() << "\"" );
969 return COMPLETE_NONPERSISTENT_MSG
;
973 * What does the reply have to say about keep-alive?
977 * If the origin server (HTTP/1.0) does not send a keep-alive
978 * header, but keeps the connection open anyway, what happens?
979 * We'll return here and http.c waits for an EOF before changing
980 * store_status to STORE_OK. Combine this with ENTRY_FWD_HDR_WAIT
981 * and an error status code, and we might have to wait until
982 * the server times out the socket.
984 if (!rep
->keep_alive
)
985 return COMPLETE_NONPERSISTENT_MSG
;
987 return COMPLETE_PERSISTENT_MSG
;
990 HttpStateData::ConnectionStatus
991 HttpStateData::persistentConnStatus() const
993 debugs(11, 3, HERE
<< serverConnection
<< " eof=" << eof
);
994 if (eof
) // already reached EOF
995 return COMPLETE_NONPERSISTENT_MSG
;
997 /* If server fd is closing (but we have not been notified yet), stop Comm
998 I/O to avoid assertions. TODO: Change Comm API to handle callers that
999 want more I/O after async closing (usually initiated by others). */
1000 // XXX: add canReceive or s/canSend/canTalkToServer/
1001 if (!Comm::IsConnOpen(serverConnection
))
1002 return COMPLETE_NONPERSISTENT_MSG
;
1005 * In chunked response we do not know the content length but we are absolutely
1006 * sure about the end of response, so we are calling the statusIfComplete to
1007 * decide if we can be persistant
1009 if (lastChunk
&& flags
.chunked
)
1010 return statusIfComplete();
1012 const HttpReply
*vrep
= virginReply();
1013 debugs(11, 5, "persistentConnStatus: content_length=" << vrep
->content_length
);
1015 const int64_t clen
= vrep
->bodySize(request
->method
);
1017 debugs(11, 5, "persistentConnStatus: clen=" << clen
);
1019 /* If the body size is unknown we must wait for EOF */
1021 return INCOMPLETE_MSG
;
1024 * If the body size is known, we must wait until we've gotten all of it. */
1027 // if (entry->mem_obj->endOffset() < vrep->content_length + vrep->hdr_sz)
1028 const int64_t body_bytes_read
= reply_bytes_read
- header_bytes_read
;
1029 debugs(11,5, "persistentConnStatus: body_bytes_read=" <<
1030 body_bytes_read
<< " content_length=" << vrep
->content_length
);
1032 if (body_bytes_read
< vrep
->content_length
)
1033 return INCOMPLETE_MSG
;
1035 if (body_bytes_truncated
> 0) // already read more than needed
1036 return COMPLETE_NONPERSISTENT_MSG
; // disable pconns
1040 * If there is no message body or we got it all, we can be persistent */
1041 return statusIfComplete();
1045 * This is the callback after some data has been read from the network
1049 HttpStateData::ReadReplyWrapper(int fd, char *buf, size_t len, comm_err_t flag, int xerrno, void *data)
1051 HttpStateData *httpState = static_cast<HttpStateData *>(data);
1052 assert (fd == httpState->serverConnection->fd);
1053 // assert(buf == readBuf->content());
1054 PROF_start(HttpStateData_readReply);
1055 httpState->readReply(len, flag, xerrno);
1056 PROF_stop(HttpStateData_readReply);
1060 /* XXX this function is too long! */
1062 HttpStateData::readReply(const CommIoCbParams
&io
)
1068 flags
.do_next_read
= 0;
1070 debugs(11, 5, HERE
<< io
.conn
<< ": len " << len
<< ".");
1072 // Bail out early on COMM_ERR_CLOSING - close handlers will tidy up for us
1073 if (io
.flag
== COMM_ERR_CLOSING
) {
1074 debugs(11, 3, "http socket closing");
1078 if (EBIT_TEST(entry
->flags
, ENTRY_ABORTED
)) {
1079 abortTransaction("store entry aborted while reading reply");
1083 // handle I/O errors
1084 if (io
.flag
!= COMM_OK
|| len
< 0) {
1085 debugs(11, 2, HERE
<< io
.conn
<< ": read failure: " << xstrerror() << ".");
1087 if (ignoreErrno(io
.xerrno
)) {
1088 flags
.do_next_read
= 1;
1090 ErrorState
*err
= new ErrorState(ERR_READ_ERROR
, HTTP_BAD_GATEWAY
, fwd
->request
);
1091 err
->xerrno
= io
.xerrno
;
1093 flags
.do_next_read
= 0;
1094 serverConnection
->close();
1102 readBuf
->appended(len
);
1103 reply_bytes_read
+= len
;
1105 DelayId delayId
= entry
->mem_obj
->mostBytesAllowed();
1106 delayId
.bytesIn(len
);
1109 kb_incr(&(statCounter
.server
.all
.kbytes_in
), len
);
1110 kb_incr(&(statCounter
.server
.http
.kbytes_in
), len
);
1111 ++ IOStats
.Http
.reads
;
1113 for (clen
= len
- 1, bin
= 0; clen
; ++bin
)
1116 ++ IOStats
.Http
.read_hist
[bin
];
1118 // update peer response time stats (%<pt)
1119 const timeval
&sent
= request
->hier
.peer_http_request_sent
;
1120 request
->hier
.peer_response_time
=
1121 sent
.tv_sec
? tvSubMsec(sent
, current_time
) : -1;
1125 * Here the RFC says we should ignore whitespace between replies, but we can't as
1126 * doing so breaks HTTP/0.9 replies beginning with witespace, and in addition
1127 * the response splitting countermeasures is extremely likely to trigger on this,
1128 * not allowing connection reuse in the first place.
1130 * 2012-02-10: which RFC? not 2068 or 2616,
1131 * tolerance there is all about whitespace between requests and header tokens.
1134 if (len
== 0) { // reached EOF?
1136 flags
.do_next_read
= 0;
1138 /* Bug 2879: Replies may terminate with \r\n then EOF instead of \r\n\r\n
1139 * Ensure here that we have at minimum two \r\n when EOF is seen.
1140 * TODO: Add eof parameter to headersEnd() and move this hack there.
1142 if (readBuf
->contentSize() && !flags
.headers_parsed
) {
1144 * Yes Henrik, there is a point to doing this. When we
1145 * called httpProcessReplyHeader() before, we didn't find
1146 * the end of headers, but now we are definately at EOF, so
1147 * we want to process the reply headers.
1149 /* Fake an "end-of-headers" to work around such broken servers */
1150 readBuf
->append("\r\n", 2);
1157 /// processes the already read and buffered response data, possibly after
1158 /// waiting for asynchronous 1xx control message processing
1160 HttpStateData::processReply()
1163 if (flags
.handling1xx
) { // we came back after handling a 1xx response
1164 debugs(11, 5, HERE
<< "done with 1xx handling");
1165 flags
.handling1xx
= false;
1166 Must(!flags
.headers_parsed
);
1169 if (!flags
.headers_parsed
) { // have not parsed headers yet?
1170 PROF_start(HttpStateData_processReplyHeader
);
1171 processReplyHeader();
1172 PROF_stop(HttpStateData_processReplyHeader
);
1174 if (!continueAfterParsingHeader()) // parsing error or need more data
1175 return; // TODO: send errors to ICAP
1177 adaptOrFinalizeReply(); // may write to, abort, or "close" the entry
1180 // kick more reads if needed and/or process the response body, if any
1181 PROF_start(HttpStateData_processReplyBody
);
1182 processReplyBody(); // may call serverComplete()
1183 PROF_stop(HttpStateData_processReplyBody
);
1187 \retval true if we can continue with processing the body or doing ICAP.
1190 HttpStateData::continueAfterParsingHeader()
1192 if (flags
.handling1xx
) {
1193 debugs(11, 5, HERE
<< "wait for 1xx handling");
1194 Must(!flags
.headers_parsed
);
1198 if (!flags
.headers_parsed
&& !eof
) {
1199 debugs(11, 9, HERE
<< "needs more at " << readBuf
->contentSize());
1200 flags
.do_next_read
= 1;
1201 /** \retval false If we have not finished parsing the headers and may get more data.
1202 * Schedules more reads to retrieve the missing data.
1204 maybeReadVirginBody(); // schedules all kinds of reads; TODO: rename
1208 /** If we are done with parsing, check for errors */
1210 err_type error
= ERR_NONE
;
1212 if (flags
.headers_parsed
) { // parsed headers, possibly with errors
1213 // check for header parsing errors
1214 if (HttpReply
*vrep
= virginReply()) {
1215 const http_status s
= vrep
->sline
.status
;
1216 const HttpVersion
&v
= vrep
->sline
.version
;
1217 if (s
== HTTP_INVALID_HEADER
&& v
!= HttpVersion(0,9)) {
1218 debugs(11, DBG_IMPORTANT
, "WARNING: HTTP: Invalid Response: Bad header encountered from " << entry
->url() << " AKA " << request
->GetHost() << request
->urlpath
.termedBuf() );
1219 error
= ERR_INVALID_RESP
;
1220 } else if (s
== HTTP_HEADER_TOO_LARGE
) {
1221 fwd
->dontRetry(true);
1222 error
= ERR_TOO_BIG
;
1224 return true; // done parsing, got reply, and no error
1227 // parsed headers but got no reply
1228 debugs(11, DBG_IMPORTANT
, "WARNING: HTTP: Invalid Response: No reply at all for " << entry
->url() << " AKA " << request
->GetHost() << request
->urlpath
.termedBuf() );
1229 error
= ERR_INVALID_RESP
;
1233 if (readBuf
->hasContent()) {
1234 error
= ERR_INVALID_RESP
;
1235 debugs(11, DBG_IMPORTANT
, "WARNING: HTTP: Invalid Response: Headers did not parse at all for " << entry
->url() << " AKA " << request
->GetHost() << request
->urlpath
.termedBuf() );
1237 error
= ERR_ZERO_SIZE_OBJECT
;
1238 debugs(11, (request
->flags
.accelerated
?DBG_IMPORTANT
:2), "WARNING: HTTP: Invalid Response: No object data received for " <<
1239 entry
->url() << " AKA " << request
->GetHost() << request
->urlpath
.termedBuf() );
1243 assert(error
!= ERR_NONE
);
1245 fwd
->fail(new ErrorState(error
, HTTP_BAD_GATEWAY
, fwd
->request
));
1246 flags
.do_next_read
= 0;
1247 serverConnection
->close();
1248 return false; // quit on error
1251 /** truncate what we read if we read too much so that writeReplyBody()
1252 writes no more than what we should have read */
1254 HttpStateData::truncateVirginBody()
1256 assert(flags
.headers_parsed
);
1258 HttpReply
*vrep
= virginReply();
1260 if (!vrep
->expectingBody(request
->method
, clen
) || clen
< 0)
1261 return; // no body or a body of unknown size, including chunked
1263 const int64_t body_bytes_read
= reply_bytes_read
- header_bytes_read
;
1264 if (body_bytes_read
- body_bytes_truncated
<= clen
)
1265 return; // we did not read too much or already took care of the extras
1267 if (const int64_t extras
= body_bytes_read
- body_bytes_truncated
- clen
) {
1268 // server sent more that the advertised content length
1269 debugs(11,5, HERE
<< "body_bytes_read=" << body_bytes_read
<<
1270 " clen=" << clen
<< '/' << vrep
->content_length
<<
1271 " body_bytes_truncated=" << body_bytes_truncated
<< '+' << extras
);
1273 readBuf
->truncate(extras
);
1274 body_bytes_truncated
+= extras
;
1279 * Call this when there is data from the origin server
1280 * which should be sent to either StoreEntry, or to ICAP...
1283 HttpStateData::writeReplyBody()
1285 truncateVirginBody(); // if needed
1286 const char *data
= readBuf
->content();
1287 int len
= readBuf
->contentSize();
1288 addVirginReplyBody(data
, len
);
1289 readBuf
->consume(len
);
1293 HttpStateData::decodeAndWriteReplyBody()
1295 const char *data
= NULL
;
1297 bool wasThereAnException
= false;
1298 assert(flags
.chunked
);
1299 assert(httpChunkDecoder
);
1300 SQUID_ENTER_THROWING_CODE();
1303 const bool doneParsing
= httpChunkDecoder
->parse(readBuf
,&decodedData
);
1304 len
= decodedData
.contentSize();
1305 data
=decodedData
.content();
1306 addVirginReplyBody(data
, len
);
1309 flags
.do_next_read
= 0;
1311 SQUID_EXIT_THROWING_CODE(wasThereAnException
);
1312 return wasThereAnException
;
1316 * processReplyBody has two purposes:
1317 * 1 - take the reply body data, if any, and put it into either
1318 * the StoreEntry, or give it over to ICAP.
1319 * 2 - see if we made it to the end of the response (persistent
1320 * connections and such)
1323 HttpStateData::processReplyBody()
1325 Ip::Address client_addr
;
1326 bool ispinned
= false;
1328 if (!flags
.headers_parsed
) {
1329 flags
.do_next_read
= 1;
1330 maybeReadVirginBody();
1335 debugs(11,5, HERE
<< "adaptationAccessCheckPending=" << adaptationAccessCheckPending
);
1336 if (adaptationAccessCheckPending
)
1342 * At this point the reply headers have been parsed and consumed.
1343 * That means header content has been removed from readBuf and
1344 * it contains only body data.
1346 if (entry
->isAccepting()) {
1347 if (flags
.chunked
) {
1348 if (!decodeAndWriteReplyBody()) {
1349 flags
.do_next_read
= 0;
1357 if (EBIT_TEST(entry
->flags
, ENTRY_ABORTED
)) {
1358 // The above writeReplyBody() call may have aborted the store entry.
1359 abortTransaction("store entry aborted while storing reply");
1362 switch (persistentConnStatus()) {
1363 case INCOMPLETE_MSG
: {
1364 debugs(11, 5, "processReplyBody: INCOMPLETE_MSG from " << serverConnection
);
1365 /* Wait for more data or EOF condition */
1366 AsyncCall::Pointer nil
;
1367 if (flags
.keepalive_broken
) {
1368 commSetConnTimeout(serverConnection
, 10, nil
);
1370 commSetConnTimeout(serverConnection
, Config
.Timeout
.read
, nil
);
1373 flags
.do_next_read
= 1;
1377 case COMPLETE_PERSISTENT_MSG
:
1378 debugs(11, 5, "processReplyBody: COMPLETE_PERSISTENT_MSG from " << serverConnection
);
1379 /* yes we have to clear all these! */
1380 commUnsetConnTimeout(serverConnection
);
1381 flags
.do_next_read
= 0;
1383 comm_remove_close_handler(serverConnection
->fd
, closeHandler
);
1384 closeHandler
= NULL
;
1385 fwd
->unregister(serverConnection
);
1387 if (request
->flags
.spoof_client_ip
)
1388 client_addr
= request
->client_addr
;
1390 if (request
->flags
.pinned
) {
1392 } else if (request
->flags
.connection_auth
&& request
->flags
.auth_sent
) {
1396 if (request
->pinnedConnection() && ispinned
) {
1397 request
->pinnedConnection()->pinConnection(serverConnection
, request
, _peer
,
1398 (request
->flags
.connection_auth
!= 0));
1400 fwd
->pconnPush(serverConnection
, request
->peer_host
? request
->peer_host
: request
->GetHost());
1403 serverConnection
= NULL
;
1407 case COMPLETE_NONPERSISTENT_MSG
:
1408 debugs(11, 5, "processReplyBody: COMPLETE_NONPERSISTENT_MSG from " << serverConnection
);
1413 maybeReadVirginBody();
1417 HttpStateData::maybeReadVirginBody()
1420 if (!Comm::IsConnOpen(serverConnection
) || fd_table
[serverConnection
->fd
].closing())
1423 // we may need to grow the buffer if headers do not fit
1424 const int minRead
= flags
.headers_parsed
? 0 :1024;
1425 const int read_size
= replyBodySpace(*readBuf
, minRead
);
1427 debugs(11,9, HERE
<< (flags
.do_next_read
? "may" : "wont") <<
1428 " read up to " << read_size
<< " bytes from " << serverConnection
);
1431 * why <2? Because delayAwareRead() won't actually read if
1432 * you ask it to read 1 byte. The delayed read request
1433 * just gets re-queued until the client side drains, then
1434 * the I/O thread hangs. Better to not register any read
1435 * handler until we get a notification from someone that
1436 * its okay to read again.
1441 if (flags
.do_next_read
) {
1442 flags
.do_next_read
= 0;
1443 typedef CommCbMemFunT
<HttpStateData
, CommIoCbParams
> Dialer
;
1444 entry
->delayAwareRead(serverConnection
, readBuf
->space(read_size
), read_size
,
1445 JobCallback(11, 5, Dialer
, this, HttpStateData::readReply
));
1449 /// called after writing the very last request byte (body, last-chunk, etc)
1451 HttpStateData::wroteLast(const CommIoCbParams
&io
)
1453 debugs(11, 5, HERE
<< serverConnection
<< ": size " << io
.size
<< ": errflag " << io
.flag
<< ".");
1454 #if URL_CHECKSUM_DEBUG
1456 entry
->mem_obj
->checkUrlChecksum();
1460 fd_bytes(io
.fd
, io
.size
, FD_WRITE
);
1461 kb_incr(&(statCounter
.server
.all
.kbytes_out
), io
.size
);
1462 kb_incr(&(statCounter
.server
.http
.kbytes_out
), io
.size
);
1465 if (io
.flag
== COMM_ERR_CLOSING
)
1469 ErrorState
*err
= new ErrorState(ERR_WRITE_ERROR
, HTTP_BAD_GATEWAY
, fwd
->request
);
1470 err
->xerrno
= io
.xerrno
;
1472 serverConnection
->close();
1479 /// successfully wrote the entire request (including body, last-chunk, etc.)
1481 HttpStateData::sendComplete()
1484 * Set the read timeout here because it hasn't been set yet.
1485 * We only set the read timeout after the request has been
1486 * fully written to the server-side. If we start the timeout
1487 * after connection establishment, then we are likely to hit
1488 * the timeout for POST/PUT requests that have very large
1491 typedef CommCbMemFunT
<HttpStateData
, CommTimeoutCbParams
> TimeoutDialer
;
1492 AsyncCall::Pointer timeoutCall
= JobCallback(11, 5,
1493 TimeoutDialer
, this, HttpStateData::httpTimeout
);
1495 commSetConnTimeout(serverConnection
, Config
.Timeout
.read
, timeoutCall
);
1497 flags
.request_sent
= 1;
1499 request
->hier
.peer_http_request_sent
= current_time
;
1502 // Close the HTTP server connection. Used by serverComplete().
1504 HttpStateData::closeServer()
1506 debugs(11,5, HERE
<< "closing HTTP server " << serverConnection
<< " this " << this);
1508 if (Comm::IsConnOpen(serverConnection
)) {
1509 fwd
->unregister(serverConnection
);
1510 comm_remove_close_handler(serverConnection
->fd
, closeHandler
);
1511 closeHandler
= NULL
;
1512 serverConnection
->close();
1517 HttpStateData::doneWithServer() const
1519 return !Comm::IsConnOpen(serverConnection
);
1523 * Fixup authentication request headers for special cases
1526 httpFixupAuthentication(HttpRequest
* request
, const HttpHeader
* hdr_in
, HttpHeader
* hdr_out
, http_state_flags flags
)
1528 http_hdr_type header
= flags
.originpeer
? HDR_AUTHORIZATION
: HDR_PROXY_AUTHORIZATION
;
1530 /* Nothing to do unless we are forwarding to a peer */
1531 if (!request
->flags
.proxying
)
1534 /* Needs to be explicitly enabled */
1535 if (!request
->peer_login
)
1538 /* Maybe already dealt with? */
1539 if (hdr_out
->has(header
))
1542 /* Nothing to do here for PASSTHRU */
1543 if (strcmp(request
->peer_login
, "PASSTHRU") == 0)
1546 /* PROXYPASS is a special case, single-signon to servers with the proxy password (basic only) */
1547 if (flags
.originpeer
&& strcmp(request
->peer_login
, "PROXYPASS") == 0 && hdr_in
->has(HDR_PROXY_AUTHORIZATION
)) {
1548 const char *auth
= hdr_in
->getStr(HDR_PROXY_AUTHORIZATION
);
1550 if (auth
&& strncasecmp(auth
, "basic ", 6) == 0) {
1551 hdr_out
->putStr(header
, auth
);
1556 /* Special mode to pass the username to the upstream cache */
1557 if (*request
->peer_login
== '*') {
1559 const char *username
= "-";
1561 if (request
->extacl_user
.size())
1562 username
= request
->extacl_user
.termedBuf();
1564 else if (request
->auth_user_request
!= NULL
)
1565 username
= request
->auth_user_request
->username();
1568 snprintf(loginbuf
, sizeof(loginbuf
), "%s%s", username
, request
->peer_login
+ 1);
1570 httpHeaderPutStrf(hdr_out
, header
, "Basic %s",
1571 old_base64_encode(loginbuf
));
1575 /* external_acl provided credentials */
1576 if (request
->extacl_user
.size() && request
->extacl_passwd
.size() &&
1577 (strcmp(request
->peer_login
, "PASS") == 0 ||
1578 strcmp(request
->peer_login
, "PROXYPASS") == 0)) {
1580 snprintf(loginbuf
, sizeof(loginbuf
), SQUIDSTRINGPH
":" SQUIDSTRINGPH
,
1581 SQUIDSTRINGPRINT(request
->extacl_user
),
1582 SQUIDSTRINGPRINT(request
->extacl_passwd
));
1583 httpHeaderPutStrf(hdr_out
, header
, "Basic %s",
1584 old_base64_encode(loginbuf
));
1588 /* Kerberos login to peer */
1589 #if HAVE_AUTH_MODULE_NEGOTIATE && HAVE_KRB5 && HAVE_GSSAPI
1590 if (strncmp(request
->peer_login
, "NEGOTIATE",strlen("NEGOTIATE")) == 0) {
1592 char *PrincipalName
=NULL
,*p
;
1593 if ((p
=strchr(request
->peer_login
,':')) != NULL
) {
1596 Token
= peer_proxy_negotiate_auth(PrincipalName
, request
->peer_host
);
1598 httpHeaderPutStrf(hdr_out
, header
, "Negotiate %s",Token
);
1602 #endif /* HAVE_KRB5 && HAVE_GSSAPI */
1604 httpHeaderPutStrf(hdr_out
, header
, "Basic %s",
1605 old_base64_encode(request
->peer_login
));
1610 * build request headers and append them to a given MemBuf
1611 * used by buildRequestPrefix()
1612 * note: initialised the HttpHeader, the caller is responsible for Clean()-ing
1615 HttpStateData::httpBuildRequestHeader(HttpRequest
* request
,
1617 const AccessLogEntryPointer
&al
,
1618 HttpHeader
* hdr_out
,
1619 const http_state_flags flags
)
1621 /* building buffer for complex strings */
1622 #define BBUF_SZ (MAX_URL+32)
1623 LOCAL_ARRAY(char, bbuf
, BBUF_SZ
);
1624 LOCAL_ARRAY(char, ntoabuf
, MAX_IPSTRLEN
);
1625 const HttpHeader
*hdr_in
= &request
->header
;
1626 const HttpHeaderEntry
*e
= NULL
;
1627 HttpHeaderPos pos
= HttpHeaderInitPos
;
1628 assert (hdr_out
->owner
== hoRequest
);
1630 /* append our IMS header */
1631 if (request
->lastmod
> -1)
1632 hdr_out
->putTime(HDR_IF_MODIFIED_SINCE
, request
->lastmod
);
1634 bool we_do_ranges
= decideIfWeDoRanges (request
);
1636 String
strConnection (hdr_in
->getList(HDR_CONNECTION
));
1638 while ((e
= hdr_in
->getEntry(&pos
)))
1639 copyOneHeaderFromClientsideRequestToUpstreamRequest(e
, strConnection
, request
, hdr_out
, we_do_ranges
, flags
);
1641 /* Abstraction break: We should interpret multipart/byterange responses
1642 * into offset-length data, and this works around our inability to do so.
1644 if (!we_do_ranges
&& request
->multipartRangeRequest()) {
1645 /* don't cache the result */
1646 request
->flags
.cachable
= 0;
1647 /* pretend it's not a range request */
1648 delete request
->range
;
1649 request
->range
= NULL
;
1650 request
->flags
.range
= 0;
1654 if (Config
.onoff
.via
) {
1656 strVia
= hdr_in
->getList(HDR_VIA
);
1657 snprintf(bbuf
, BBUF_SZ
, "%d.%d %s",
1658 request
->http_ver
.major
,
1659 request
->http_ver
.minor
, ThisCache
);
1660 strListAdd(&strVia
, bbuf
, ',');
1661 hdr_out
->putStr(HDR_VIA
, strVia
.termedBuf());
1665 if (request
->flags
.accelerated
) {
1666 /* Append Surrogate-Capabilities */
1667 String
strSurrogate(hdr_in
->getList(HDR_SURROGATE_CAPABILITY
));
1669 snprintf(bbuf
, BBUF_SZ
, "%s=\"Surrogate/1.0 ESI/1.0\"", Config
.Accel
.surrogate_id
);
1671 snprintf(bbuf
, BBUF_SZ
, "%s=\"Surrogate/1.0\"", Config
.Accel
.surrogate_id
);
1673 strListAdd(&strSurrogate
, bbuf
, ',');
1674 hdr_out
->putStr(HDR_SURROGATE_CAPABILITY
, strSurrogate
.termedBuf());
1677 /** \pre Handle X-Forwarded-For */
1678 if (strcmp(opt_forwarded_for
, "delete") != 0) {
1680 String strFwd
= hdr_in
->getList(HDR_X_FORWARDED_FOR
);
1682 if (strFwd
.size() > 65536/2) {
1683 // There is probably a forwarding loop with Via detection disabled.
1684 // If we do nothing, String will assert on overflow soon.
1685 // TODO: Terminate all transactions with huge XFF?
1688 static int warnedCount
= 0;
1689 if (warnedCount
++ < 100) {
1690 const char *url
= entry
? entry
->url() : urlCanonical(request
);
1691 debugs(11, DBG_IMPORTANT
, "Warning: likely forwarding loop with " << url
);
1695 if (strcmp(opt_forwarded_for
, "on") == 0) {
1696 /** If set to ON - append client IP or 'unknown'. */
1697 if ( request
->client_addr
.IsNoAddr() )
1698 strListAdd(&strFwd
, "unknown", ',');
1700 strListAdd(&strFwd
, request
->client_addr
.NtoA(ntoabuf
, MAX_IPSTRLEN
), ',');
1701 } else if (strcmp(opt_forwarded_for
, "off") == 0) {
1702 /** If set to OFF - append 'unknown'. */
1703 strListAdd(&strFwd
, "unknown", ',');
1704 } else if (strcmp(opt_forwarded_for
, "transparent") == 0) {
1705 /** If set to TRANSPARENT - pass through unchanged. */
1706 } else if (strcmp(opt_forwarded_for
, "truncate") == 0) {
1707 /** If set to TRUNCATE - drop existing list and replace with client IP or 'unknown'. */
1708 if ( request
->client_addr
.IsNoAddr() )
1711 strFwd
= request
->client_addr
.NtoA(ntoabuf
, MAX_IPSTRLEN
);
1713 if (strFwd
.size() > 0)
1714 hdr_out
->putStr(HDR_X_FORWARDED_FOR
, strFwd
.termedBuf());
1716 /** If set to DELETE - do not copy through. */
1718 /* append Host if not there already */
1719 if (!hdr_out
->has(HDR_HOST
)) {
1720 if (request
->peer_domain
) {
1721 hdr_out
->putStr(HDR_HOST
, request
->peer_domain
);
1722 } else if (request
->port
== urlDefaultPort(request
->protocol
)) {
1723 /* use port# only if not default */
1724 hdr_out
->putStr(HDR_HOST
, request
->GetHost());
1726 httpHeaderPutStrf(hdr_out
, HDR_HOST
, "%s:%d",
1728 (int) request
->port
);
1732 /* append Authorization if known in URL, not in header and going direct */
1733 if (!hdr_out
->has(HDR_AUTHORIZATION
)) {
1734 if (!request
->flags
.proxying
&& request
->login
&& *request
->login
) {
1735 httpHeaderPutStrf(hdr_out
, HDR_AUTHORIZATION
, "Basic %s",
1736 old_base64_encode(request
->login
));
1740 /* Fixup (Proxy-)Authorization special cases. Plain relaying dealt with above */
1741 httpFixupAuthentication(request
, hdr_in
, hdr_out
, flags
);
1743 /* append Cache-Control, add max-age if not there already */
1745 HttpHdrCc
*cc
= hdr_in
->getCc();
1748 cc
= new HttpHdrCc();
1750 #if 0 /* see bug 2330 */
1751 /* Set no-cache if determined needed but not found */
1752 if (request
->flags
.nocache
)
1753 EBIT_SET(cc
->mask
, CC_NO_CACHE
);
1756 /* Add max-age only without no-cache */
1757 if (!cc
->hasMaxAge() && !cc
->noCache()) {
1759 entry
? entry
->url() : urlCanonical(request
);
1760 cc
->maxAge(getMaxAge(url
));
1764 /* Enforce sibling relations */
1765 if (flags
.only_if_cached
)
1766 cc
->onlyIfCached(true);
1773 /* maybe append Connection: keep-alive */
1774 if (flags
.keepalive
) {
1775 hdr_out
->putStr(HDR_CONNECTION
, "keep-alive");
1778 /* append Front-End-Https */
1779 if (flags
.front_end_https
) {
1780 if (flags
.front_end_https
== 1 || request
->protocol
== AnyP::PROTO_HTTPS
)
1781 hdr_out
->putStr(HDR_FRONT_END_HTTPS
, "On");
1784 if (flags
.chunked_request
) {
1785 // Do not just copy the original value so that if the client-side
1786 // starts decode other encodings, this code may remain valid.
1787 hdr_out
->putStr(HDR_TRANSFER_ENCODING
, "chunked");
1790 /* Now mangle the headers. */
1791 if (Config2
.onoff
.mangle_request_headers
)
1792 httpHdrMangleList(hdr_out
, request
, ROR_REQUEST
);
1794 if (Config
.request_header_add
&& !Config
.request_header_add
->empty())
1795 httpHdrAdd(hdr_out
, request
, al
, *Config
.request_header_add
);
1797 strConnection
.clean();
1801 * Decides whether a particular header may be cloned from the received Clients request
1802 * to our outgoing fetch request.
1805 copyOneHeaderFromClientsideRequestToUpstreamRequest(const HttpHeaderEntry
*e
, const String strConnection
, const HttpRequest
* request
, HttpHeader
* hdr_out
, const int we_do_ranges
, const http_state_flags flags
)
1807 debugs(11, 5, "httpBuildRequestHeader: " << e
->name
<< ": " << e
->value
);
1811 /** \par RFC 2616 sect 13.5.1 - Hop-by-Hop headers which Squid should not pass on. */
1813 case HDR_PROXY_AUTHORIZATION
:
1814 /** \par Proxy-Authorization:
1815 * Only pass on proxy authentication to peers for which
1816 * authentication forwarding is explicitly enabled
1818 if (!flags
.originpeer
&& flags
.proxying
&& request
->peer_login
&&
1819 (strcmp(request
->peer_login
, "PASS") == 0 ||
1820 strcmp(request
->peer_login
, "PROXYPASS") == 0 ||
1821 strcmp(request
->peer_login
, "PASSTHRU") == 0)) {
1822 hdr_out
->addEntry(e
->clone());
1826 /** \par RFC 2616 sect 13.5.1 - Hop-by-Hop headers which Squid does not pass on. */
1828 case HDR_CONNECTION
: /** \par Connection: */
1829 case HDR_TE
: /** \par TE: */
1830 case HDR_KEEP_ALIVE
: /** \par Keep-Alive: */
1831 case HDR_PROXY_AUTHENTICATE
: /** \par Proxy-Authenticate: */
1832 case HDR_TRAILER
: /** \par Trailer: */
1833 case HDR_UPGRADE
: /** \par Upgrade: */
1834 case HDR_TRANSFER_ENCODING
: /** \par Transfer-Encoding: */
1837 /** \par OTHER headers I haven't bothered to track down yet. */
1839 case HDR_AUTHORIZATION
:
1840 /** \par WWW-Authorization:
1841 * Pass on WWW authentication */
1843 if (!flags
.originpeer
) {
1844 hdr_out
->addEntry(e
->clone());
1846 /** \note In accelerators, only forward authentication if enabled
1847 * (see also httpFixupAuthentication for special cases)
1849 if (request
->peer_login
&&
1850 (strcmp(request
->peer_login
, "PASS") == 0 ||
1851 strcmp(request
->peer_login
, "PASSTHRU") == 0 ||
1852 strcmp(request
->peer_login
, "PROXYPASS") == 0)) {
1853 hdr_out
->addEntry(e
->clone());
1861 * Normally Squid rewrites the Host: header.
1862 * However, there is one case when we don't: If the URL
1863 * went through our redirector and the admin configured
1864 * 'redir_rewrites_host' to be off.
1866 if (request
->peer_domain
)
1867 hdr_out
->putStr(HDR_HOST
, request
->peer_domain
);
1868 else if (request
->flags
.redirected
&& !Config
.onoff
.redir_rewrites_host
)
1869 hdr_out
->addEntry(e
->clone());
1871 /* use port# only if not default */
1873 if (request
->port
== urlDefaultPort(request
->protocol
)) {
1874 hdr_out
->putStr(HDR_HOST
, request
->GetHost());
1876 httpHeaderPutStrf(hdr_out
, HDR_HOST
, "%s:%d",
1878 (int) request
->port
);
1884 case HDR_IF_MODIFIED_SINCE
:
1885 /** \par If-Modified-Since:
1886 * append unless we added our own;
1887 * \note at most one client's ims header can pass through */
1889 if (!hdr_out
->has(HDR_IF_MODIFIED_SINCE
))
1890 hdr_out
->addEntry(e
->clone());
1894 case HDR_MAX_FORWARDS
:
1895 /** \par Max-Forwards:
1896 * pass only on TRACE or OPTIONS requests */
1897 if (request
->method
== METHOD_TRACE
|| request
->method
== METHOD_OPTIONS
) {
1898 const int64_t hops
= e
->getInt64();
1901 hdr_out
->putInt64(HDR_MAX_FORWARDS
, hops
- 1);
1908 * If Via is disabled then forward any received header as-is.
1909 * Otherwise leave for explicit updated addition later. */
1911 if (!Config
.onoff
.via
)
1912 hdr_out
->addEntry(e
->clone());
1920 case HDR_REQUEST_RANGE
:
1921 /** \par Range:, If-Range:, Request-Range:
1922 * Only pass if we accept ranges */
1924 hdr_out
->addEntry(e
->clone());
1928 case HDR_PROXY_CONNECTION
: // SHOULD ignore. But doing so breaks things.
1931 case HDR_CONTENT_LENGTH
:
1932 // pass through unless we chunk; also, keeping this away from default
1933 // prevents request smuggling via Connection: Content-Length tricks
1934 if (!flags
.chunked_request
)
1935 hdr_out
->addEntry(e
->clone());
1938 case HDR_X_FORWARDED_FOR
:
1940 case HDR_CACHE_CONTROL
:
1941 /** \par X-Forwarded-For:, Cache-Control:
1942 * handled specially by Squid, so leave off for now.
1943 * append these after the loop if needed */
1946 case HDR_FRONT_END_HTTPS
:
1947 /** \par Front-End-Https:
1948 * Pass thru only if peer is configured with front-end-https */
1949 if (!flags
.front_end_https
)
1950 hdr_out
->addEntry(e
->clone());
1956 * pass on all other header fields
1957 * which are NOT listed by the special Connection: header. */
1959 if (strConnection
.size()>0 && strListIsMember(&strConnection
, e
->name
.termedBuf(), ',')) {
1960 debugs(11, 2, "'" << e
->name
<< "' header cropped by Connection: definition");
1964 hdr_out
->addEntry(e
->clone());
1969 HttpStateData::decideIfWeDoRanges (HttpRequest
* request
)
1972 /* decide if we want to do Ranges ourselves
1973 * and fetch the whole object now)
1974 * We want to handle Ranges ourselves iff
1975 * - we can actually parse client Range specs
1976 * - the specs are expected to be simple enough (e.g. no out-of-order ranges)
1977 * - reply will be cachable
1978 * (If the reply will be uncachable we have to throw it away after
1979 * serving this request, so it is better to forward ranges to
1980 * the server and fetch only the requested content)
1983 int64_t roffLimit
= request
->getRangeOffsetLimit();
1985 if (NULL
== request
->range
|| !request
->flags
.cachable
1986 || request
->range
->offsetLimitExceeded(roffLimit
) || request
->flags
.connection_auth
)
1989 debugs(11, 8, "decideIfWeDoRanges: range specs: " <<
1990 request
->range
<< ", cachable: " <<
1991 request
->flags
.cachable
<< "; we_do_ranges: " << result
);
1996 /* build request prefix and append it to a given MemBuf;
1997 * return the length of the prefix */
1999 HttpStateData::buildRequestPrefix(MemBuf
* mb
)
2001 const int offset
= mb
->size
;
2002 HttpVersion
httpver(1,1);
2004 if (_peer
&& !_peer
->options
.originserver
)
2007 url
= request
->urlpath
.termedBuf();
2008 mb
->Printf("%s %s %s/%d.%d\r\n",
2009 RequestMethodStr(request
->method
),
2010 url
&& *url
? url
: "/",
2011 AnyP::ProtocolType_str
[httpver
.protocol
],
2012 httpver
.major
,httpver
.minor
);
2013 /* build and pack headers */
2015 HttpHeader
hdr(hoRequest
);
2017 httpBuildRequestHeader(request
, entry
, fwd
->al
, &hdr
, flags
);
2019 if (request
->flags
.pinned
&& request
->flags
.connection_auth
)
2020 request
->flags
.auth_sent
= 1;
2021 else if (hdr
.has(HDR_AUTHORIZATION
))
2022 request
->flags
.auth_sent
= 1;
2024 packerToMemInit(&p
, mb
);
2029 /* append header terminator */
2030 mb
->append(crlf
, 2);
2031 return mb
->size
- offset
;
2034 /* This will be called when connect completes. Write request. */
2036 HttpStateData::sendRequest()
2040 debugs(11, 5, HERE
<< serverConnection
<< ", request " << request
<< ", this " << this << ".");
2042 if (!Comm::IsConnOpen(serverConnection
)) {
2043 debugs(11,3, HERE
<< "cannot send request to closing " << serverConnection
);
2044 assert(closeHandler
!= NULL
);
2048 typedef CommCbMemFunT
<HttpStateData
, CommTimeoutCbParams
> TimeoutDialer
;
2049 AsyncCall::Pointer timeoutCall
= JobCallback(11, 5,
2050 TimeoutDialer
, this, HttpStateData::httpTimeout
);
2051 commSetConnTimeout(serverConnection
, Config
.Timeout
.lifetime
, timeoutCall
);
2052 flags
.do_next_read
= 1;
2053 maybeReadVirginBody();
2055 if (request
->body_pipe
!= NULL
) {
2056 if (!startRequestBodyFlow()) // register to receive body data
2058 typedef CommCbMemFunT
<HttpStateData
, CommIoCbParams
> Dialer
;
2059 requestSender
= JobCallback(11,5,
2060 Dialer
, this, HttpStateData::sentRequestBody
);
2062 Must(!flags
.chunked_request
);
2063 // use chunked encoding if we do not know the length
2064 if (request
->content_length
< 0)
2065 flags
.chunked_request
= 1;
2067 assert(!requestBodySource
);
2068 typedef CommCbMemFunT
<HttpStateData
, CommIoCbParams
> Dialer
;
2069 requestSender
= JobCallback(11,5,
2070 Dialer
, this, HttpStateData::wroteLast
);
2073 if (_peer
!= NULL
) {
2074 if (_peer
->options
.originserver
) {
2076 flags
.originpeer
= 1;
2079 flags
.originpeer
= 0;
2083 flags
.originpeer
= 0;
2087 * Is keep-alive okay for all request methods?
2089 if (request
->flags
.must_keepalive
)
2090 flags
.keepalive
= 1;
2091 else if (!Config
.onoff
.server_pconns
)
2092 flags
.keepalive
= 0;
2093 else if (_peer
== NULL
)
2094 flags
.keepalive
= 1;
2095 else if (_peer
->stats
.n_keepalives_sent
< 10)
2096 flags
.keepalive
= 1;
2097 else if ((double) _peer
->stats
.n_keepalives_recv
/
2098 (double) _peer
->stats
.n_keepalives_sent
> 0.50)
2099 flags
.keepalive
= 1;
2102 /*The old code here was
2103 if (neighborType(_peer, request) == PEER_SIBLING && ...
2104 which is equivalent to:
2105 if (neighborType(_peer, NULL) == PEER_SIBLING && ...
2107 if (((_peer->type == PEER_MULTICAST && p->options.mcast_siblings) ||
2108 _peer->type == PEER_SIBLINGS ) && _peer->options.allow_miss)
2109 flags.only_if_cached = 1;
2111 But I suppose it was a bug
2113 if (neighborType(_peer
, request
) == PEER_SIBLING
&&
2114 !_peer
->options
.allow_miss
)
2115 flags
.only_if_cached
= 1;
2117 flags
.front_end_https
= _peer
->front_end_https
;
2121 request
->peer_host
=_peer
?_peer
->host
:NULL
;
2122 buildRequestPrefix(&mb
);
2124 debugs(11, 2, "HTTP Server " << serverConnection
);
2125 debugs(11, 2, "HTTP Server REQUEST:\n---------\n" << mb
.buf
<< "\n----------");
2127 Comm::Write(serverConnection
, &mb
, requestSender
);
2132 HttpStateData::getMoreRequestBody(MemBuf
&buf
)
2134 // parent's implementation can handle the no-encoding case
2135 if (!flags
.chunked_request
)
2136 return ServerStateData::getMoreRequestBody(buf
);
2140 Must(requestBodySource
!= NULL
);
2141 if (!requestBodySource
->getMoreData(raw
))
2142 return false; // no request body bytes to chunk yet
2144 // optimization: pre-allocate buffer size that should be enough
2145 const mb_size_t rawDataSize
= raw
.contentSize();
2146 // we may need to send: hex-chunk-size CRLF raw-data CRLF last-chunk
2147 buf
.init(16 + 2 + rawDataSize
+ 2 + 5, raw
.max_capacity
);
2149 buf
.Printf("%x\r\n", static_cast<unsigned int>(rawDataSize
));
2150 buf
.append(raw
.content(), rawDataSize
);
2153 Must(rawDataSize
> 0); // we did not accidently created last-chunk above
2155 // Do not send last-chunk unless we successfully received everything
2156 if (receivedWholeRequestBody
) {
2157 Must(!flags
.sentLastChunk
);
2158 flags
.sentLastChunk
= true;
2159 buf
.append("0\r\n\r\n", 5);
2166 httpStart(FwdState
*fwd
)
2168 debugs(11, 3, "httpStart: \"" << RequestMethodStr(fwd
->request
->method
) << " " << fwd
->entry
->url() << "\"" );
2169 AsyncJob::Start(new HttpStateData(fwd
));
2173 HttpStateData::start()
2175 if (!sendRequest()) {
2176 debugs(11, 3, "httpStart: aborted");
2177 mustStop("HttpStateData::start failed");
2181 ++ statCounter
.server
.all
.requests
;
2182 ++ statCounter
.server
.http
.requests
;
2185 * We used to set the read timeout here, but not any more.
2186 * Now its set in httpSendComplete() after the full request,
2187 * including request body, has been written to the server.
2191 /// if broken posts are enabled for the request, try to fix and return true
2193 HttpStateData::finishingBrokenPost()
2195 #if USE_HTTP_VIOLATIONS
2196 if (!Config
.accessList
.brokenPosts
) {
2197 debugs(11, 5, HERE
<< "No brokenPosts list");
2201 ACLFilledChecklist
ch(Config
.accessList
.brokenPosts
, originalRequest(), NULL
);
2202 if (ch
.fastCheck() != ACCESS_ALLOWED
) {
2203 debugs(11, 5, HERE
<< "didn't match brokenPosts");
2207 if (!Comm::IsConnOpen(serverConnection
)) {
2208 debugs(11, 3, HERE
<< "ignoring broken POST for closed " << serverConnection
);
2209 assert(closeHandler
!= NULL
);
2210 return true; // prevent caller from proceeding as if nothing happened
2213 debugs(11, 3, "finishingBrokenPost: fixing broken POST");
2214 typedef CommCbMemFunT
<HttpStateData
, CommIoCbParams
> Dialer
;
2215 requestSender
= JobCallback(11,5,
2216 Dialer
, this, HttpStateData::wroteLast
);
2217 Comm::Write(serverConnection
, "\r\n", 2, requestSender
, NULL
);
2221 #endif /* USE_HTTP_VIOLATIONS */
2224 /// if needed, write last-chunk to end the request body and return true
2226 HttpStateData::finishingChunkedRequest()
2228 if (flags
.sentLastChunk
) {
2229 debugs(11, 5, HERE
<< "already sent last-chunk");
2233 Must(receivedWholeRequestBody
); // or we should not be sending last-chunk
2234 flags
.sentLastChunk
= true;
2236 typedef CommCbMemFunT
<HttpStateData
, CommIoCbParams
> Dialer
;
2237 requestSender
= JobCallback(11,5, Dialer
, this, HttpStateData::wroteLast
);
2238 Comm::Write(serverConnection
, "0\r\n\r\n", 5, requestSender
, NULL
);
2243 HttpStateData::doneSendingRequestBody()
2245 ServerStateData::doneSendingRequestBody();
2246 debugs(11,5, HERE
<< serverConnection
);
2248 // do we need to write something after the last body byte?
2249 if (flags
.chunked_request
&& finishingChunkedRequest())
2251 if (!flags
.chunked_request
&& finishingBrokenPost())
2257 // more origin request body data is available
2259 HttpStateData::handleMoreRequestBodyAvailable()
2261 if (eof
|| !Comm::IsConnOpen(serverConnection
)) {
2262 // XXX: we should check this condition in other callbacks then!
2263 // TODO: Check whether this can actually happen: We should unsubscribe
2264 // as a body consumer when the above condition(s) are detected.
2265 debugs(11, DBG_IMPORTANT
, HERE
<< "Transaction aborted while reading HTTP body");
2269 assert(requestBodySource
!= NULL
);
2271 if (requestBodySource
->buf().hasContent()) {
2272 // XXX: why does not this trigger a debug message on every request?
2274 if (flags
.headers_parsed
&& !flags
.abuse_detected
) {
2275 flags
.abuse_detected
= 1;
2276 debugs(11, DBG_IMPORTANT
, "http handleMoreRequestBodyAvailable: Likely proxy abuse detected '" << request
->client_addr
<< "' -> '" << entry
->url() << "'" );
2278 if (virginReply()->sline
.status
== HTTP_INVALID_HEADER
) {
2279 serverConnection
->close();
2285 HttpStateData::handleMoreRequestBodyAvailable();
2288 // premature end of the request body
2290 HttpStateData::handleRequestBodyProducerAborted()
2292 ServerStateData::handleRequestBodyProducerAborted();
2293 if (entry
->isEmpty()) {
2294 debugs(11, 3, "request body aborted: " << serverConnection
);
2295 // We usually get here when ICAP REQMOD aborts during body processing.
2296 // We might also get here if client-side aborts, but then our response
2297 // should not matter because either client-side will provide its own or
2298 // there will be no response at all (e.g., if the the client has left).
2299 ErrorState
*err
= new ErrorState(ERR_ICAP_FAILURE
, HTTP_INTERNAL_SERVER_ERROR
, fwd
->request
);
2300 err
->detailError(ERR_DETAIL_SRV_REQMOD_REQ_BODY
);
2304 abortTransaction("request body producer aborted");
2307 // called when we wrote request headers(!) or a part of the body
2309 HttpStateData::sentRequestBody(const CommIoCbParams
&io
)
2312 kb_incr(&statCounter
.server
.http
.kbytes_out
, io
.size
);
2314 ServerStateData::sentRequestBody(io
);
2317 // Quickly abort the transaction
2318 // TODO: destruction should be sufficient as the destructor should cleanup,
2319 // including canceling close handlers
2321 HttpStateData::abortTransaction(const char *reason
)
2323 debugs(11,5, HERE
<< "aborting transaction for " << reason
<<
2324 "; " << serverConnection
<< ", this " << this);
2326 if (Comm::IsConnOpen(serverConnection
)) {
2327 serverConnection
->close();
2331 fwd
->handleUnregisteredServerEnd();
2332 mustStop("HttpStateData::abortTransaction");