From: Francesco Chemolli Date: Tue, 11 Sep 2012 15:11:33 +0000 (+0200) Subject: Refactored some RequestFlags with getters and setters. X-Git-Tag: sourceformat-review-1~6^2~8 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b9068fc084b5809c0fc824d371b846b85932da69;p=thirdparty%2Fsquid.git Refactored some RequestFlags with getters and setters. --- diff --git a/src/RequestFlags.h b/src/RequestFlags.h index 027274c62b..e066bf60f5 100644 --- a/src/RequestFlags.h +++ b/src/RequestFlags.h @@ -41,10 +41,12 @@ public: fail_on_validation_err(0), stale_if_hit(0), accelerated(0), ignore_cc(0), intercepted(0), hostVerified(0), spoof_client_ip(0), internal(0), internalclient(0), must_keepalive(0), pinned(0), - canRePin(0), chunked_reply(0), stream_error(0), sslPeek_(false), + canRePin(0), no_direct(false), chunked_reply(false), + stream_error(false), sslPeek_(false), done_follow_x_forwarded_for(!FOLLOW_X_FORWARDED_FOR), sslBumped_(false), destinationIPLookedUp_(false), resetTCP_(false), - isRanged_(false) { + isRanged_(false) + { #if USE_HTTP_VIOLATIONS nocache_hack = 0; #endif @@ -82,13 +84,6 @@ public: unsigned int pinned :1; /* Request sent on a pinned connection */ unsigned int canRePin :1; ///< OK to reopen a failed pinned connection unsigned int auth_sent :1; /* Authentication forwarded */ - unsigned int no_direct :1; /* Deny direct forwarding unless overriden by always_direct. Used in accelerator mode */ - unsigned int chunked_reply :1; /**< Reply with chunked transfer encoding */ - unsigned int stream_error :1; /**< Whether stream error has occured */ - -#if FOLLOW_X_FORWARDED_FOR - /* TODO: move from conditional definition to conditional setting */ -#endif /* FOLLOW_X_FORWARDED_FOR */ // When adding new flags, please update cloneAdaptationImmune() as needed. bool resetTCP() const; @@ -120,8 +115,23 @@ public: bool sslPeek() const { return sslPeek_; } void setSslPeek() { sslPeek_=true; } void clearSslPeek() { sslPeek_=false; } -private: + bool hadStreamError() const { return stream_error; } + void setStreamError() { stream_error = true; } + void clearStreamError() { stream_error = false; } + + bool isReplyChunked() const { return chunked_reply; } + void markReplyChunked() { chunked_reply = true; } + + void setNoDirect() { no_direct=true; } + bool noDirect() { return no_direct; } + +private: + /** Deny direct forwarding unless overriden by always_direct. + * Used in accelerator mode */ + bool no_direct :1; + bool chunked_reply :1; /**< Reply with chunked transfer encoding */ + bool stream_error :1; /**< Whether stream error has occured */ bool sslPeek_ :1; ///< internal ssl-bump request to get server cert /* done_follow_x_forwarded_for is set by default to the opposite of * compilation option FOLLOW_X_FORWARDED_FOR (so that it returns diff --git a/src/client_side.cc b/src/client_side.cc index 009c43d6ac..c6619b6a29 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -985,7 +985,7 @@ ClientSocketContext::sendBody(HttpReply * rep, StoreIOBuffer bodyData) { assert(rep == NULL); - if (!multipartRangeRequest() && !http->request->flags.chunked_reply) { + if (!multipartRangeRequest() && !http->request->flags.isReplyChunked()) { size_t length = lengthToSend(bodyData.range()); noteSentBodyBytes (length); AsyncCall::Pointer call = commCbCall(33, 5, "clientWriteBodyComplete", @@ -1394,7 +1394,7 @@ ClientSocketContext::sendStartOfMessage(HttpReply * rep, StoreIOBuffer bodyData) if (bodyData.data && bodyData.length) { if (multipartRangeRequest()) packRange(bodyData, mb); - else if (http->request->flags.chunked_reply) { + else if (http->request->flags.isReplyChunked()) { packChunk(bodyData, *mb); } else { size_t length = lengthToSend(bodyData.range()); @@ -1449,8 +1449,9 @@ clientSocketRecipient(clientStreamNode * node, ClientHttpRequest * http, // After sending Transfer-Encoding: chunked (at least), always send // the last-chunk if there was no error, ignoring responseFinishedOrFailed. - const bool mustSendLastChunk = http->request->flags.chunked_reply && - !http->request->flags.stream_error && !context->startOfOutput(); + const bool mustSendLastChunk = http->request->flags.isReplyChunked() && + !http->request->flags.hadStreamError() && + !context->startOfOutput(); if (responseFinishedOrFailed(rep, receivedData) && !mustSendLastChunk) { context->writeComplete(context->clientConnection, NULL, 0, COMM_OK); PROF_stop(clientSocketRecipient); @@ -2656,8 +2657,9 @@ clientProcessRequest(ConnStateData *conn, HttpParser *hp, ClientSocketContext *c request->flags.canRePin = request->flags.sslBumped() && conn->pinning.pinned; request->flags.ignore_cc = conn->port->ignore_cc; // TODO: decouple http->flags.accel from request->flags.sslBumped - request->flags.no_direct = (request->flags.accelerated && !request->flags.sslBumped()) ? - !conn->port->allow_direct : 0; + if (request->flags.accelerated && !request->flags.sslBumped()) + if (!conn->port->allow_direct) + request->flags.setNoDirect(); #if USE_AUTH if (request->flags.sslBumped()) { if (conn->auth_user_request != NULL) diff --git a/src/client_side_reply.cc b/src/client_side_reply.cc index 64fd47d9f8..9bc6519e2b 100644 --- a/src/client_side_reply.cc +++ b/src/client_side_reply.cc @@ -1042,7 +1042,7 @@ clientReplyContext::checkTransferDone() if (http->flags.done_copying) return 1; - if (http->request->flags.chunked_reply && !flags.complete) { + if (http->request->flags.isReplyChunked() && !flags.complete) { // last-chunk was not sent return 0; } @@ -1488,7 +1488,7 @@ clientReplyContext::buildReplyHeader() request->flags.proxy_keepalive && reply->bodySize(request->method) < 0) { debugs(88, 3, "clientBuildReplyHeader: chunked reply"); - request->flags.chunked_reply = 1; + request->flags.markReplyChunked(); hdr->putStr(HDR_TRANSFER_ENCODING, "chunked"); } @@ -1825,7 +1825,7 @@ clientReplyContext::sendStreamError(StoreIOBuffer const &result) debugs(88, 5, "clientReplyContext::sendStreamError: A stream error has occured, marking as complete and sending no data."); StoreIOBuffer localTempBuffer; flags.complete = 1; - http->request->flags.stream_error = 1; + http->request->flags.setStreamError(); localTempBuffer.flags.error = result.flags.error; clientStreamCallback((clientStreamNode*)http->client_stream.head->data, http, NULL, localTempBuffer); diff --git a/src/peer_select.cc b/src/peer_select.cc index ae61be4faf..f965ee2059 100644 --- a/src/peer_select.cc +++ b/src/peer_select.cc @@ -443,7 +443,7 @@ peerSelectFoo(ps_state * ps) ps->acl_checklist = new ACLFilledChecklist(Config.accessList.NeverDirect, request, NULL); ps->acl_checklist->nonBlockingCheck(peerCheckNeverDirectDone, ps); return; - } else if (request->flags.no_direct) { + } else if (request->flags.noDirect()) { /** if we are accelerating, direct is not an option. */ ps->direct = DIRECT_NO; debugs(44, 3, "peerSelectFoo: direct = " << DirectStr[ps->direct] << " (forced non-direct)");