http.cc
Go to the documentation of this file.
75static void copyOneHeaderFromClientsideRequestToUpstreamRequest(const HttpHeaderEntry *e, const String strConnection, const HttpRequest * request,
250 neighborsHtcpClear(e, e->mem_obj->request.getRaw(), HttpRequestMethod(Http::METHOD_HEAD), HTCP_CLR_INVALIDATION);
260 HttpHdrScTarget *sctusable = reply->surrogate_control->getMergedTarget(Config.Accel.surrogate_id);
364 // RFC 2616 section 14.9.1 - MUST NOT cache any response with CC:private in a shared cache like Squid.
380 // RFC 2068, sec 14.9.4 - MUST NOT cache any response with Authentication UNLESS certain CC controls are present
405 // some. The caching+revalidate is not exactly unsafe though with Squids interpretation of no-cache
408 debugs(22, 3, "Authenticated but server reply Cache-Control:no-cache (equivalent to must-revalidate)");
421 // NP: response CC:no-cache is equivalent to CC:must-revalidate,max-age=0. We MAY cache, and do so.
502 case Http::scBadRequest: // no sharing; perhaps the server did not like something specific to this request
619 debugs(11, DBG_IMPORTANT, "keepaliveAccounting: Impossible keep-alive header from '" << entry->url() << "'" );
655 /* Attempt to parse the first line; this will define where the protocol, status, reason-phrase and header begin */
719 newrep->sources |= request->url.getScheme() == AnyP::PROTO_HTTPS ? Http::Message::srcHttps : Http::Message::srcHttp;
721 if (newrep->sline.version.protocol == AnyP::PROTO_HTTP && Http::Is1xx(newrep->sline.status())) {
810 const auto err = new ErrorState(ERR_INVALID_RESP, Http::scBadGateway, request.getRaw(), fwd->al);
929 if (rep.header.hasListMember(Http::HdrType::PROXY_SUPPORT, "Session-Based-Authentication", ','))
1032 const bool ccMustRevalidate = (rep->cache_control->hasProxyRevalidate() || rep->cache_control->hasMustRevalidate());
1325 debugs(11, DBG_IMPORTANT, "WARNING: HTTP: Invalid Response: Bad header encountered from " << entry->url() << " AKA " << request->url);
1341 debugs(11, DBG_IMPORTANT, "WARNING: HTTP: Invalid Response: No reply at all for " << entry->url() << " AKA " << request->url);
1348 debugs(11, DBG_IMPORTANT, "WARNING: HTTP: Invalid Response: Headers did not parse at all for " << entry->url() << " AKA " << request->url);
1351 debugs(11, (request->flags.accelerated?DBG_IMPORTANT:2), "WARNING: HTTP: Invalid Response: No object data received for " << entry->url() << " AKA " << request->url);
1612 const int limitBuffer = (flags.headers_parsed ? Config.readAheadGap : Config.maxReplyHeaderSize);
1616 debugs(11, 7, "will not read up to " << limitBuffer << ". buffer has (" << inBuf.length() << "/" << inBuf.spaceSize() << ") from " << serverConnection);
1624 const size_t read_size = calcBufferSpaceToReserve(inBuf.spaceSize(), (limitBuffer - inBuf.length()));
1627 debugs(11, 7, "will not read up to " << read_size << " into buffer (" << inBuf.length() << "/" << inBuf.spaceSize() << ") from " << serverConnection);
1638 " read up to " << read_size << " bytes info buf(" << inBuf.length() << "/" << inBuf.spaceSize() <<
1724httpFixupAuthentication(HttpRequest * request, const HttpHeader * hdr_in, HttpHeader * hdr_out, const Http::StateFlags &flags)
1738 const auto header = flags.toOrigin ? Http::HdrType::AUTHORIZATION : Http::HdrType::PROXY_AUTHORIZATION;
1779 blen = base64_encode_update(&ctx, loginbuf, strlen(username), reinterpret_cast<const uint8_t*>(username));
1780 blen += base64_encode_update(&ctx, loginbuf+blen, strlen(request->peer_login +1), reinterpret_cast<const uint8_t*>(request->peer_login +1));
1791 blen = base64_encode_update(&ctx, loginbuf, request->extacl_user.size(), reinterpret_cast<const uint8_t*>(request->extacl_user.rawBuf()));
1793 blen += base64_encode_update(&ctx, loginbuf+blen, request->extacl_passwd.size(), reinterpret_cast<const uint8_t*>(request->extacl_passwd.rawBuf()));
1798 // if no external user credentials are available to fake authentication with PASS acts like PASSTHRU
1823 blen = base64_encode_update(&ctx, loginbuf, strlen(request->peer_login), reinterpret_cast<const uint8_t*>(request->peer_login));
1866 copyOneHeaderFromClientsideRequestToUpstreamRequest(e, strConnection, request, hdr_out, we_do_ranges, flags);
1948 static char result[base64_encode_len(MAX_URL*2)]; // should be big enough for a single URI segment
1951 size_t blen = base64_encode_update(&ctx, result, request->url.userInfo().length(), reinterpret_cast<const uint8_t*>(request->url.userInfo().rawContent()));
2039 Config.http_upgrade_request_protocols->forApplicable(offeredProto, [&ch, offeredStr, offeredStrLen, &upgradeOut] (const SBuf &cfgProto, const acl_access *guard) {
2086copyOneHeaderFromClientsideRequestToUpstreamRequest(const HttpHeaderEntry *e, const String strConnection, const HttpRequest * request, HttpHeader * hdr_out, const int we_do_ranges, const Http::StateFlags &flags)
2173 else if (Config.onoff.cache_miss_revalidate || !request->flags.cachable || request->flags.auth)
2186 if (hdr_out->hasListMember(Http::HdrType::IF_MATCH, "*", ',') || Config.onoff.cache_miss_revalidate || !request->flags.cachable || request->flags.auth)
2571 debugs(11, DBG_IMPORTANT, "http handleMoreRequestBodyAvailable: Likely proxy abuse detected '" << request->client_addr << "' -> '" << entry->url() << "'" );
2595 const auto err = new ErrorState(ERR_ICAP_FAILURE, Http::scInternalServerError, fwd->request, fwd->al);
2623 : answer(HttpStateData::ReuseDecision::reuseNot), reason(nullptr), entry(e), statusCode(code) {}
2626HttpStateData::ReuseDecision::make(const HttpStateData::ReuseDecision::Answers ans, const char *why)
RefCount< AsyncCallT< Dialer > > asyncCall(int aDebugSection, int aDebugLevel, const char *aName, const Dialer &aDialer)
Definition: AsyncCall.h:156
#define JobCallback(dbgSection, dbgLevel, Dialer, job, method)
Convenience macro to create a Dialer-based job callback.
Definition: AsyncJobCalls.h:69
#define CallJobHere(debugSection, debugLevel, job, Class, method)
Definition: AsyncJobCalls.h:58
#define CallJobHere1(debugSection, debugLevel, job, Class, method, arg1)
Definition: AsyncJobCalls.h:63
ErrorDetail::Pointer MakeNamedErrorDetail(const char *name)
Definition: Detail.cc:54
PconnPool * fwdPconnPool
a collection of previously used persistent Squid-to-peer HTTP(S) connections
Definition: FwdState.cc:78
void httpHeaderPutStrf(HttpHeader *hdr, Http::HdrType id, const char *fmt,...)
Definition: HttpHeaderTools.cc:54
void httpHdrMangleList(HttpHeader *l, HttpRequest *request, const AccessLogEntryPointer &al, req_or_rep_t req_or_rep)
Definition: HttpHeaderTools.cc:336
bool httpHeaderHasConnDir(const HttpHeader *hdr, const SBuf &directive)
Definition: HttpHeaderTools.cc:91
int strListGetItem(const String *str, char del, const char **item, int *ilen, const char **pos)
Definition: StrList.cc:86
void strListAdd(String &str, const char *item, const size_t itemSize, const char delimiter)
Appends the given item of a given size to a delimiter-separated list in str.
Definition: StrList.cc:18
int strListIsMember(const String *list, const SBuf &m, char del)
Definition: StrList.cc:46
std::ostream & CurrentException(std::ostream &os)
prints active (i.e., thrown but not yet handled) exception
Definition: TextException.cc:88
void error(char *format,...)
size_t base64_encode_update(struct base64_encode_ctx *ctx, char *dst, size_t length, const uint8_t *src)
Definition: base64.c:265
size_t base64_encode_final(struct base64_encode_ctx *ctx, char *dst)
Definition: base64.c:308
Definition: FilledChecklist.h:32
AccessLogEntry::Pointer al
info for the future access.log, and external ACL
Definition: FilledChecklist.h:101
void syncAle(HttpRequest *adaptedRequest, const char *logUri) const override
assigns uninitialized adapted_request and url ALE components
Definition: FilledChecklist.cc:121
Definition: ProtocolVersion.h:24
Definition: AsyncJob.h:32
struct CachePeer::@28 options
struct CachePeer::@26 stats
Definition: Client.h:35
virtual HttpRequestPointer originalRequest()
a hack to reach HttpStateData::orignal_request
Definition: Client.cc:570
virtual bool getMoreRequestBody(MemBuf &buf)
either fill buf with available [encoded] request body bytes or return false
Definition: Client.cc:438
virtual void handleRequestBodyProducerAborted()=0
Definition: Client.cc:351
size_t calcBufferSpaceToReserve(const size_t space, const size_t wantSpace) const
determine how much space the buffer needs to reserve
Definition: Client.cc:1063
void addVirginReplyBody(const char *buf, ssize_t len)
Definition: Client.cc:1038
void markParsedVirginReplyAsWhole(const char *reasonWeAreSure)
Definition: Client.cc:158
virtual void sentRequestBody(const CommIoCbParams &io)=0
Definition: Client.cc:364
virtual void haveParsedReplyHeaders()
called when we have final (possibly adapted) reply headers; kids extend
Definition: Client.cc:537
Definition: CommCalls.h:166
Definition: CommCalls.h:128
Definition: CommCalls.h:114
Definition: CommCalls.h:134
parameters for the async notePinnedConnectionBecameIdle() call
Definition: client_side.h:183
noteTakeServerConnectionControl() callback parameter
Definition: client_side.h:213
Definition: client_side.h:84
virtual void noteTakeServerConnectionControl(ServerConnectionContext)
Definition: client_side.h:229
void sendControlMsg(HttpControlMsg) override
called to send the 1xx message and notify the Source
Definition: client_side.cc:3651
Definition: DelayId.h:22
Definition: errorpage.h:89
Definition: FwdState.h:53
Comm::ConnectionPointer const & serverConnection() const
Definition: FwdState.h:104
bundles HTTP 1xx reply and the "successfully forwarded" callback
Definition: HttpControlMsg.h:47
Definition: HttpHdrCc.h:44
bool hasNoCacheWithoutParameters() const
Definition: HttpHdrCc.h:88
bool offsetLimitExceeded(const int64_t limit) const
Definition: HttpHdrRange.cc:510
Definition: HttpHdrScTarget.h:25
HttpHdrScTarget * getMergedTarget(const char *ourtarget)
Definition: HttpHdrSc.cc:294
Definition: HttpHeader.h:51
Definition: HttpHeader.h:75
HttpHeaderEntry * getEntry(HttpHeaderPos *pos) const
Definition: HttpHeader.cc:584
void addVia(const AnyP::ProtocolVersion &ver, const HttpHeader *from=nullptr)
Definition: HttpHeader.cc:946
void packInto(Packable *p, bool mask_sensitive_info=false) const
Definition: HttpHeader.cc:540
int hasListMember(Http::HdrType id, const char *member, const char separator) const
Definition: HttpHeader.cc:1663
Definition: HttpReply.h:25
bool expectingBody(const HttpRequestMethod &, int64_t &) const override
Definition: HttpReply.cc:528
Definition: RequestMethod.h:27
Definition: HttpRequest.h:49
CbcPointer< ConnStateData > clientConnectionManager
Definition: HttpRequest.h:232
bool forcedBodyContinuation
whether we have responded with HTTP 100 or FTP 150 already
Definition: HttpRequest.h:194
String etag
A strong etag of the cached entry. Used for refreshing that entry.
Definition: HttpRequest.h:191
void ignoreRange(const char *reason)
forgets about the cached Range header (for a reason)
Definition: HttpRequest.cc:621
Auth::UserRequest::Pointer auth_user_request
Definition: HttpRequest.h:127
bool canHandle1xx() const
whether the client is likely to be able to handle a 1xx reply
Definition: HttpRequest.cc:635
const SBuf & effectiveRequestUri() const
RFC 7230 section 5.5 - Effective Request URI.
Definition: HttpRequest.cc:744
assists in making and relaying entry caching/sharing decision
Definition: http.h:30
ReuseDecision(const StoreEntry *e, const Http::StatusCode code)
Definition: http.cc:2622
Answers make(const Answers ans, const char *why)
stores the corresponding decision
Definition: http.cc:2626
Definition: http.h:23
void httpStateConnClosed(const CommCloseCbParams ¶ms)
Definition: http.cc:137
void handleRequestBodyProducerAborted() override
Definition: http.cc:2586
Http1::ResponseParserPointer hp
Parser being used at present to parse the HTTP/ICY server response.
Definition: http.h:152
String * upgradeHeaderOut
Upgrade header value sent to the origin server or cache peer.
Definition: http.h:73
void handle1xx(HttpReply *msg)
ignore or start forwarding the 1xx response (a.k.a., control message)
Definition: http.cc:747
const char * blockSwitchingProtocols(const HttpReply &) const
Definition: http.cc:824
static void httpBuildRequestHeader(HttpRequest *request, StoreEntry *entry, const AccessLogEntryPointer &al, HttpHeader *hdr_out, const Http::StateFlags &flags)
Definition: http.cc:1835
static bool decideIfWeDoRanges(HttpRequest *orig_request)
Definition: http.cc:2264
ConnectionStatus persistentConnStatus() const
Definition: http.cc:1113
void sendComplete()
successfully wrote the entire request (including body, last-chunk, etc.)
Definition: http.cc:1683
void httpTimeout(const CommTimeoutCbParams ¶ms)
Definition: http.cc:145
ReuseDecision::Answers reusableReply(ReuseDecision &decision)
Definition: http.cc:295
void haveParsedReplyHeaders() override
called when we have final (possibly adapted) reply headers; kids extend
Definition: http.cc:938
bool getMoreRequestBody(MemBuf &buf) override
either fill buf with available [encoded] request body bytes or return false
Definition: http.cc:2425
void abortAll(const char *reason) override
abnormal transaction termination; reason is for debugging only
Definition: http.cc:2615
void processSurrogateControl(HttpReply *)
Definition: http.cc:257
void markPrematureReplyBodyEofFailure()
called on a premature EOF discovered when reading response body
Definition: http.cc:1392
bool mayReadVirginReplyBody() const override
whether we may receive more virgin response body bytes
Definition: http.cc:1574
bool maybeMakeSpaceAvailable(bool grow)
Definition: http.cc:1609
bool peerSupportsConnectionPinning() const
Definition: http.cc:880
virtual void handleMoreRequestBodyAvailable()
Definition: http.cc:2554
void wroteLast(const CommIoCbParams &io)
called after writing the very last request byte (body, last-chunk, etc)
Definition: http.cc:1646
void noteDelayAwareReadChance() override
Definition: http.cc:1163
const Comm::ConnectionPointer & dataConnection() const override
Definition: http.cc:131
void sentRequestBody(const CommIoCbParams &io) override
Definition: http.cc:2606
void proceedAfter1xx()
restores state and resumes processing after 1xx is ignored or forwarded
Definition: http.cc:851
bool finishingChunkedRequest()
if needed, write last-chunk to end the request body and return true
Definition: http.cc:2521
bool finishingBrokenPost()
if broken posts are enabled for the request, try to fix and return true
Definition: http.cc:2486
void forApplicable(const ProtocolView &, const Visitor &) const
Definition: HttpUpgradeProtocolAccess.h:106
Definition: ResponseParser.h:30
Definition: TeChunkedParser.h:52
void setPayloadBuffer(MemBuf *parsedContent)
set the buffer to be used to store decoded chunk data
Definition: TeChunkedParser.h:58
Definition: StateFlags.h:16
bool peering
Whether the next TCP hop is a cache_peer, including originserver.
Definition: StateFlags.h:40
bool keepalive
whether the Squid-sent request offers to keep the connection persistent
Definition: StateFlags.h:21
bool toOriginPeer() const
Whether the next TCP/HTTP hop is an originserver cache_peer.
Definition: StateFlags.h:56
unsigned int front_end_https
send "Front-End-Https: On" header (off/on/auto=2)
Definition: StateFlags.h:18
AnyP::ProtocolVersion version
breakdown of protocol version label: (HTTP/ICY) and (0.9/1.0/1.1)
Definition: StatusLine.h:65
void set(const AnyP::ProtocolVersion &newVersion, Http::StatusCode newStatus, const char *newReason=nullptr)
Definition: StatusLine.cc:35
Http::StatusCode status() const
retrieve the status code for this status line
Definition: StatusLine.h:45
struct IoStats::@75 Http
Definition: Address.h:41
char * toStr(char *buf, const unsigned int blen, int force=AF_UNSPEC) const
Definition: Address.cc:792
Definition: MemBuf.h:24
Definition: AsyncJobCalls.h:91
void appendf(const char *fmt,...) PRINTF_FORMAT_ARG2
Append operation with printf-style arguments.
Definition: Packable.h:61
void push(const Comm::ConnectionPointer &serverConn, const char *domain)
Definition: pconn.cc:412
a reference to a protocol name[/version] string; no 0-termination is assumed
Definition: HttpUpgradeProtocolAccess.h:20
Definition: Range.h:19
struct SquidConfig::@107 accessList
struct SquidConfig::@106 onoff
struct SquidConfig::@100 Accel
struct SquidConfig::@93 Timeout
HttpUpgradeProtocolAccess * http_upgrade_request_protocols
http_upgrade_request_protocols
Definition: SquidConfig.h:469
int detect_broken_server_pconns
Definition: SquidConfig.h:314
struct StatCounters::@123::@133 all
struct StatCounters::@123::@133 http
struct StatCounters::@123 server
Definition: Store.h:42
size_t bytesWanted(Range< size_t > const aRange, bool ignoreDelayPool=false) const
Definition: store.cc:212
Definition: SquidString.h:26
bool canGrowBy(const size_type growthLen) const
whether appending growthLen characters is safe (i.e., unlikely to assert)
Definition: SquidString.h:124
void veto()
makes decision() false regardless of past or future support() calls
Definition: SupportOrVeto.h:29
Definition: AsyncJobCalls.h:108
int commSetConnTimeout(const Comm::ConnectionPointer &conn, time_t timeout, AsyncCall::Pointer &callback)
Definition: comm.cc:595
AsyncCall::Pointer comm_add_close_handler(int fd, CLCB *handler, void *data)
Definition: comm.cc:949
void comm_remove_close_handler(int fd, CLCB *handler, void *data)
Definition: comm.cc:978
int commUnsetConnTimeout(const Comm::ConnectionPointer &conn)
Definition: comm.cc:621
char * opt_forwarded_for
int neighbors_do_private_keys
IoStats IOStats
#define REFRESH_OVERRIDE(flag)
static StoreEntry * findPreviouslyCachedEntry(StoreEntry *newEntry)
Definition: http.cc:158
SBuf httpMakeVaryMark(HttpRequest *request, HttpReply const *reply)
Definition: http.cc:588
#define BBUF_SZ
static void httpFixupAuthentication(HttpRequest *request, const HttpHeader *hdr_in, HttpHeader *hdr_out, const Http::StateFlags &flags)
Definition: http.cc:1724
std::ostream & operator<<(std::ostream &os, const HttpStateData::ReuseDecision &d)
Definition: http.cc:2633
static void copyOneHeaderFromClientsideRequestToUpstreamRequest(const HttpHeaderEntry *e, const String strConnection, const HttpRequest *request, HttpHeader *hdr_out, const int we_do_ranges, const Http::StateFlags &)
Definition: http.cc:2086
static void httpMaybeRemovePublic(StoreEntry *, Http::StatusCode)
Definition: http.cc:168
static void assembleVaryKey(String &vary, SBuf &vstr, const HttpRequest &request)
assemble a variant key (vary-mark) from the given Vary header and HTTP request
Definition: http.cc:552
#define MAX_IPSTRLEN
Length of buffer that needs to be allocated to old a null-terminated IP-string.
Definition: forward.h:25
const char * ProtocolType_str[]
void Read(const Comm::ConnectionPointer &conn, AsyncCall::Pointer &callback)
Definition: Read.cc:40
void Write(const Comm::ConnectionPointer &conn, const char *buf, int size, AsyncCall::Pointer &callback, FREE *free_func)
Definition: Write.cc:33
bool Is1xx(const int sc)
whether this is an informational 1xx response status code
Definition: StatusCode.h:92
bool IsReforwardableStatus(StatusCode)
whether to send the request to another peer based on the current response status code
Definition: StatusCode.cc:281
AnyP::ProtocolVersion ProtocolVersion(unsigned int aMajor, unsigned int aMinor)
HTTP version label information.
Definition: ProtocolVersion.h:19
void Controller::create() STUB void Controller Controller nil
Definition: stub_libstore.cc:19
void neighborsHtcpClear(StoreEntry *e, HttpRequest *req, const HttpRequestMethod &method, htcp_clr_reason reason)
Definition: neighbors.cc:1673
peer_t neighborType(const CachePeer *p, const AnyP::Uri &url)
Definition: neighbors.cc:114
#define PEER_PROXY_NEGOTIATE_NOKEYTAB
Definition: peer_proxy_negotiate_auth.h:12
StoreEntry * storeGetPublicByRequestMethod(HttpRequest *req, const HttpRequestMethod &method, const KeyScope keyScope)
Definition: store.cc:496
StoreEntry * storeGetPublicByRequest(HttpRequest *req, const KeyScope keyScope)
Definition: store.cc:502
StoreEntry * storeGetPublic(const char *uri, const HttpRequestMethod &method)
Definition: store.cc:490
Definition: base64.h:69