#include "base/RefCount.h"
#include "comm/Connection.h"
#include "HttpHeader.h"
-#include "HttpVersion.h"
+#include "http/ProtocolVersion.h"
#include "HttpRequestMethod.h"
#include "HierarchyLogEntry.h"
#include "icp_opcode.h"
HttpRequestMethod method;
int code;
const char *content_type;
- HttpVersion version;
+ Http::ProtocolVersion version;
bool timedout; ///< terminated due to a lifetime or I/O timeout
bool aborted; ///< other abnormal termination (e.g., I/O error)
bool
HttpMsg::persistent() const
{
- if (http_ver > HttpVersion(1, 0)) {
+ if (http_ver > Http::ProtocolVersion(1, 0)) {
/*
* for modern versions of HTTP: persistent unless there is
* a "Connection: close" header.
#include "HttpHeader.h"
#include "HttpRequestMethod.h"
#include "http/StatusCode.h"
-#include "HttpVersion.h"
+#include "http/ProtocolVersion.h"
#include "typedefs.h"
/// common parts of HttpRequest and HttpReply
bool persistent() const;
public:
- HttpVersion http_ver;
+ Http::ProtocolVersion http_ver;
HttpHeader header;
/* rv->cache_control */
/* rv->content_range */
/* rv->keep_alive */
- HttpVersion ver(1,1);
- httpStatusLineSet(&rv->sline, ver, Http::scNotModified, NULL);
+ httpStatusLineSet(&rv->sline, Http::ProtocolVersion(1,1), Http::scNotModified, NULL);
for (t = 0; ImsEntries[t] != HDR_OTHER; ++t)
if ((e = header.findEntry(ImsEntries[t])))
const char *ctype, int64_t clen, time_t lmt, time_t expiresTime)
{
HttpHeader *hdr;
- HttpVersion ver(1,1);
- httpStatusLineSet(&sline, ver, status, reason);
+ httpStatusLineSet(&sline, Http::ProtocolVersion(1,1), status, reason);
hdr = &header;
hdr->putStr(HDR_SERVER, visible_appname_string);
hdr->putStr(HDR_MIME_VERSION, "1.0");
HttpReply::redirect(Http::StatusCode status, const char *loc)
{
HttpHeader *hdr;
- HttpVersion ver(1,1);
- httpStatusLineSet(&sline, ver, status, httpStatusString(status));
+ httpStatusLineSet(&sline, Http::ProtocolVersion(1,1), status, httpStatusString(status));
hdr = &header;
hdr->putStr(HDR_SERVER, APP_FULLNAME);
hdr->putTime(HDR_DATE, squid_curtime);
#if DEAD_CODE
/** do everything in one call: init, set, pack, clean, return MemBuf */
-MemBuf *httpPackedReply(HttpVersion ver, Http::StatusCode status, const char *ctype, int64_t clen, time_t lmt, time_t expires);
+MemBuf *httpPackedReply(Http::ProtocolVersion ver, Http::StatusCode status, const char *ctype, int64_t clen, time_t lmt, time_t expires);
#endif
/* Sync changes here with HttpReply.cc */
{
// old clients do not support 1xx unless they sent Expect: 100-continue
// (we reject all other HDR_EXPECT values so just check for HDR_EXPECT)
- if (http_ver <= HttpVersion(1,0) && !header.has(HDR_EXPECT))
+ if (http_ver <= Http::ProtocolVersion(1,0) && !header.has(HDR_EXPECT))
return false;
// others must support 1xx control messages
void
httpStatusLineInit(HttpStatusLine * sline)
{
- HttpVersion version;
- httpStatusLineSet(sline, version, Http::scNone, NULL);
+ httpStatusLineSet(sline, Http::ProtocolVersion(), Http::scNone, NULL);
}
void
httpStatusLineClean(HttpStatusLine * sline)
{
- HttpVersion version;
- httpStatusLineSet(sline, version, Http::scInternalServerError, NULL);
+ httpStatusLineSet(sline, Http::ProtocolVersion(), Http::scInternalServerError, NULL);
}
/* set values */
void
-httpStatusLineSet(HttpStatusLine * sline, HttpVersion version, Http::StatusCode status, const char *reason)
+httpStatusLineSet(HttpStatusLine * sline, Http::ProtocolVersion version, Http::StatusCode status, const char *reason)
{
assert(sline);
sline->protocol = AnyP::PROTO_HTTP;
#ifndef SQUID_HTTPSTATUSLINE_H
#define SQUID_HTTPSTATUSLINE_H
+#include "http/ProtocolVersion.h"
#include "http/StatusCode.h"
-#include "HttpVersion.h"
-#include "anyp/ProtocolType.h"
#include "SquidString.h"
class Packer;
*/
AnyP::ProtocolType protocol;
- HttpVersion version; ///< breakdown of protocol version labels: 0.9 1.0 1.1
+ Http::ProtocolVersion version; ///< breakdown of protocol version labels: 0.9 1.0 1.1
Http::StatusCode status; ///< status code. ie 200 404
const char *reason; ///< points to a _constant_ string (default or supplied), never free()d */
};
void httpStatusLineInit(HttpStatusLine * sline);
void httpStatusLineClean(HttpStatusLine * sline);
/* set/get values */
-void httpStatusLineSet(HttpStatusLine * sline, HttpVersion version,
+void httpStatusLineSet(HttpStatusLine * sline, Http::ProtocolVersion version,
Http::StatusCode status, const char *reason);
const char *httpStatusLineReason(const HttpStatusLine * sline);
/* parse/pack */
+++ /dev/null
-
-/*
- *
- * SQUID Web Proxy Cache http://www.squid-cache.org/
- * ----------------------------------------------------------
- *
- * Squid is the result of efforts by numerous individuals from
- * the Internet community; see the CONTRIBUTORS file for full
- * details. Many organizations have provided support for Squid's
- * development; see the SPONSORS file for full details. Squid is
- * Copyrighted (C) 2001 by the Regents of the University of
- * California; see the COPYRIGHT file for full details. Squid
- * incorporates software developed and/or copyrighted by other
- * sources; see the CREDITS file for full details.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA.
- *
- * Copyright (c) 2003, Robert Collins <robertc@squid-cache.org>
- */
-
-#ifndef SQUID_HTTPVERSION_H
-#define SQUID_HTTPVERSION_H
-
-#include "anyp/ProtocolVersion.h"
-
-class HttpVersion : public AnyP::ProtocolVersion
-{
-public:
- HttpVersion() : AnyP::ProtocolVersion(AnyP::PROTO_HTTP,0,0) {}
-
- HttpVersion(unsigned int aMajor, unsigned int aMinor) : AnyP::ProtocolVersion(AnyP::PROTO_HTTP,aMajor,aMinor) {}
-};
-
-#endif /* SQUID_HTTPVERSION_H */
HttpRequest.h \
HttpRequestMethod.cc \
HttpRequestMethod.h \
- HttpVersion.h \
ICP.h \
icp_opcode.h \
icp_v2.cc \
namespace AnyP
{
+/**
+ * Stores a protocol version label.
+ * For example HTTP/1.1 or ICY/1.0 or FTP/2.0
+ */
class ProtocolVersion
{
minor = aMinor;
}
- ProtocolType protocol;
- unsigned int major;
- unsigned int minor;
+ ProtocolType protocol; ///< which protocol this version is for
+ unsigned int major; ///< major version number
+ unsigned int minor; ///< minor version number
bool operator==(const ProtocolVersion& that) const {
if (this->protocol != that.protocol)
#endif
static CTCB clientLifetimeTimeout;
static ClientSocketContext *parseHttpRequestAbort(ConnStateData * conn, const char *uri);
-static ClientSocketContext *parseHttpRequest(ConnStateData *, HttpParser *, HttpRequestMethod *, HttpVersion *);
+static ClientSocketContext *parseHttpRequest(ConnStateData *, HttpParser *, HttpRequestMethod *, Http::ProtocolVersion *);
#if USE_IDENT
static IDCB clientIdentDone;
#endif
* a ClientSocketContext structure on success or failure.
*/
static ClientSocketContext *
-parseHttpRequest(ConnStateData *csd, HttpParser *hp, HttpRequestMethod * method_p, HttpVersion *http_ver)
+parseHttpRequest(ConnStateData *csd, HttpParser *hp, HttpRequestMethod * method_p, Http::ProtocolVersion *http_ver)
{
char *req_hdr = NULL;
char *end;
}
/* Request line is valid here .. */
- *http_ver = HttpVersion(hp->req.v_maj, hp->req.v_min);
+ *http_ver = Http::ProtocolVersion(hp->req.v_maj, hp->req.v_min);
/* This call scans the entire request, not just the headers */
if (hp->req.v_maj > 0) {
#endif // USE_SSL
static void
-clientProcessRequest(ConnStateData *conn, HttpParser *hp, ClientSocketContext *context, const HttpRequestMethod& method, HttpVersion http_ver)
+clientProcessRequest(ConnStateData *conn, HttpParser *hp, ClientSocketContext *context, const HttpRequestMethod& method, Http::ProtocolVersion http_ver)
{
ClientHttpRequest *http = context->http;
HttpRequest::Pointer request;
{
HttpRequestMethod method;
bool parsed_req = false;
- HttpVersion http_ver;
debugs(33, 5, HERE << clientConnection << ": attempting to parse");
HttpParserInit(&parser_, in.buf, in.notYetUsed);
/* Process request */
+ Http::ProtocolVersion http_ver;
ClientSocketContext *context = parseHttpRequest(this, &parser_, &method, &http_ver);
PROF_stop(parseHttpRequest);
const bool maySendChunkedReply = !request->multipartRangeRequest() &&
reply->sline.protocol == AnyP::PROTO_HTTP && // response is HTTP
- (request->http_ver >= HttpVersion(1, 1));
+ (request->http_ver >= Http::ProtocolVersion(1, 1));
/* Check whether we should send keep-alive */
if (!Config.onoff.error_pconns && reply->sline.status >= 400 && !request->flags.mustKeepalive) {
if (reply->sline.protocol == AnyP::PROTO_HTTP) {
/* RFC 2616 requires us to advertise our 1.1 version (but only on real HTTP traffic) */
- reply->sline.version = HttpVersion(1,1);
+ reply->sline.version = Http::ProtocolVersion(1,1);
}
/* do header conversions */
request->my_addr.SetPort(0);
/* Our version is HTTP/1.1 */
- HttpVersion http_ver(1,1);
- request->http_ver = http_ver;
+ request->http_ver = Http::ProtocolVersion(1,1);
http->request = request;
HTTPMSGLOCK(http->request);
status = httpStatus;
else {
// Use 307 for HTTP/1.1 non-GET/HEAD requests.
- if (request->method != Http::METHOD_GET && request->method != Http::METHOD_HEAD && request->http_ver >= HttpVersion(1,1))
+ if (request->method != Http::METHOD_GET && request->method != Http::METHOD_HEAD && request->http_ver >= Http::ProtocolVersion(1,1))
status = Http::scTemporaryRedirect;
}
if (!parsed && error > 0) { // unrecoverable parsing error
debugs(11, 3, "processReplyHeader: Non-HTTP-compliant header: '" << readBuf->content() << "'");
flags.headers_parsed = true;
- newrep->sline.version = HttpVersion(1,1);
+ newrep->sline.version = Http::ProtocolVersion(1,1);
newrep->sline.status = error;
HttpReply *vrep = setVirginReply(newrep);
entry->replaceHttpReply(vrep);
// check for header parsing errors
if (HttpReply *vrep = virginReply()) {
const Http::StatusCode s = vrep->sline.status;
- const HttpVersion &v = vrep->sline.version;
- if (s == Http::scInvalidHeader && v != HttpVersion(0,9)) {
+ const Http::ProtocolVersion &v = vrep->sline.version;
+ if (s == Http::scInvalidHeader && v != Http::ProtocolVersion(0,9)) {
debugs(11, DBG_IMPORTANT, "WARNING: HTTP: Invalid Response: Bad header encountered from " << entry->url() << " AKA " << request->GetHost() << request->urlpath.termedBuf() );
error = ERR_INVALID_RESP;
} else if (s == Http::scHeaderTooLarge) {
HttpStateData::buildRequestPrefix(MemBuf * mb)
{
const int offset = mb->size;
- HttpVersion httpver(1,1);
+ /* Uses a local httpver variable to print the HTTP/1.1 label
+ * since the HttpRequest may have an older version label.
+ * XXX: This could create protocol bugs as the headers sent and
+ * flow control should all be based on the HttpRequest version
+ * not the one we are sending. Needs checking.
+ */
+ Http::ProtocolVersion httpver(1,1);
const char * url;
if (_peer && !_peer->options.originserver)
url = entry->url();
libsquid_http_la_SOURCES = \
MethodType.cc \
MethodType.h \
+ ProtocolVersion.h \
StatusCode.h
MethodType.cc: MethodType.h $(top_srcdir)/src/mk-string-arrays.awk
--- /dev/null
+#ifndef SQUID_HTTP_PROTOCOLVERSION_H
+#define SQUID_HTTP_PROTOCOLVERSION_H
+
+#include "anyp/ProtocolVersion.h"
+
+namespace Http
+{
+
+/**
+ * Stores HTTP version label information.
+ * For example HTTP/1.0
+ */
+class ProtocolVersion : public AnyP::ProtocolVersion
+{
+public:
+ ProtocolVersion() : AnyP::ProtocolVersion(AnyP::PROTO_HTTP,0,0) {}
+
+ ProtocolVersion(unsigned int aMajor, unsigned int aMinor) : AnyP::ProtocolVersion(AnyP::PROTO_HTTP,aMajor,aMinor) {}
+};
+
+}; // namespace Http
+
+#endif /* SQUID_HTTP_PROTOCOLVERSION_H */
HTTPMSGLOCK(ex->r);
assert(NULL != ex->r);
- ex->r->http_ver = HttpVersion(1,1);
+ ex->r->http_ver = Http::ProtocolVersion(1,1);
ex->connstate = STATE_HEADER;
ex->e = storeCreateEntry(uri, uri, RequestFlags(), Http::METHOD_GET);
ex->buf_sz = NETDB_REQBUF_SZ;