}
}
#endif
-
-void
-AnyP::PortCfg::setTransport(const char *aProtocol)
-{
- // HTTP/1.0 not supported because we are version 1.1 which contains a superset of 1.0
- // and RFC 2616 requires us to upgrade 1.0 to 1.1
-
- if (strcasecmp("http", aProtocol) == 0 || strcmp("HTTP/1.1", aProtocol) == 0)
- transport = AnyP::ProtocolVersion(AnyP::PROTO_HTTP, 1,1);
-
- else if (strcasecmp("https", aProtocol) == 0 || strcmp("HTTPS/1.1", aProtocol) == 0)
- transport = AnyP::ProtocolVersion(AnyP::PROTO_HTTPS, 1,1);
-
- else if (strcasecmp("ftp", aProtocol) == 0)
- transport = AnyP::ProtocolVersion(AnyP::PROTO_FTP, 1,1);
-
- else
- fatalf("http(s)_port protocol=%s is not supported\n", aProtocol);
-}
void configureSslServerContext();
#endif
- /**
- * Set this ports transport type from a string representation.
- * Unknown transport type representations will halt Squid.
- * Supports: HTTP, HTTP/1.1, HTTPS, HTTPS/1.1, and FTP.
- */
- void setTransport(const char *aProtocol);
-
PortCfgPointer next;
Ip::Address s;
#include "eui/Config.h"
#include "ExternalACL.h"
#include "format/Format.h"
+#include "ftp/Elements.h"
#include "globals.h"
#include "HttpHeaderTools.h"
#include "HttpRequestMethod.h"
}
}
+/// parses the protocol= option of the *_port directive, returning parsed value
+/// unsupported option values result in a fatal error message
+static AnyP::ProtocolVersion
+parsePortProtocol(const char *value)
+{
+ // HTTP/1.0 not supported because we are version 1.1 which contains a superset of 1.0
+ // and RFC 2616 requires us to upgrade 1.0 to 1.1
+ if (strcasecmp("http", value) == 0 || strcmp("HTTP/1.1", value) == 0)
+ return AnyP::ProtocolVersion(AnyP::PROTO_HTTP, 1,1);
+
+ if (strcasecmp("https", value) == 0 || strcmp("HTTPS/1.1", value) == 0)
+ return AnyP::ProtocolVersion(AnyP::PROTO_HTTPS, 1,1);
+
+ if (strcasecmp("ftp", value) == 0)
+ return AnyP::ProtocolVersion(AnyP::PROTO_FTP,
+ Ftp::ProtocolVersion().major, Ftp::ProtocolVersion().minor);
+
+ fatalf("%s directive does not support protocol=%s\n", cfg_directive, value);
+ return AnyP::ProtocolVersion(); // not reached
+}
+
static void
parse_port_option(AnyP::PortCfgPointer &s, char *token)
{
debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: protocol option requires Acceleration mode flag.");
self_destruct();
}
- s->setTransport(token + 9);
+ s->transport = parsePortProtocol(token + 9);
} else if (strcmp(token, "allow-direct") == 0) {
if (!s->flags.accelSurrogate) {
debugs(3, DBG_CRITICAL, "FATAL: http(s)_port: allow-direct option requires Acceleration mode flag.");
add_http_port(char *portspec)
{
AnyP::PortCfgPointer s = new AnyP::PortCfg();
- s->setTransport("HTTP");
+ s->transport = parsePortProtocol("HTTP");
parsePortSpecification(s, portspec);
// we may need to merge better if the above returns a list with clones
assert(s->next == NULL);
}
AnyP::PortCfgPointer s = new AnyP::PortCfg();
- s->setTransport(protocol);
+ s->transport = parsePortProtocol(protocol); // default; protocol=... overwrites
parsePortSpecification(s, token);
/* parse options ... */
#include "HttpReply.h"
#include "SBuf.h"
+// FTP does not have a notion of a "protocol version" but we need something for
+// compatibility with the current HttpMsg wrapping layer. We use version 1.1:
+// * some ICAP services probably expect /1.0 or /1.1 when parsing HTTP headers;
+// * FTP commands are sent on a "persistent by default" connection, just like
+// HTTP/1.1. Using 1.1 leads to fewer exceptions in current code shared by
+// HTTP and FTP.
+AnyP::ProtocolVersion
+Ftp::ProtocolVersion()
+{
+ return AnyP::ProtocolVersion(AnyP::PROTO_FTP, 1, 1);
+}
+
HttpReply *
Ftp::HttpReplyWrapper(const int ftpStatus, const char *ftpReason, const Http::StatusCode httpStatus, const int64_t clen)
{
HttpReply *const reply = new HttpReply;
- reply->sline.set(Http::ProtocolVersion(1, 1), httpStatus);
+
+ Http::ProtocolVersion httpVersion = Http::ProtocolVersion(
+ Ftp::ProtocolVersion().major, Ftp::ProtocolVersion().minor);
+ reply->sline.set(httpVersion, httpStatus);
+
HttpHeader &header = reply->header;
header.putTime(HDR_DATE, squid_curtime);
{
class SBuf;
class HttpReply;
+namespace AnyP
+{
+class ProtocolVersion;
+}
+
namespace Ftp
{
+/// Protocol version to use in HttpMsg structures wrapping FTP messages.
+AnyP::ProtocolVersion ProtocolVersion();
+
/// Create an internal HttpReply structure to house FTP control response info.
HttpReply *HttpReplyWrapper(const int ftpStatus, const char *ftpReason, const Http::StatusCode httpStatus, const int64_t clen);
connector(),
reader()
{
- assert(xact->squidPort->transport.protocol == AnyP::PROTO_FTP);
flags.readMore = false; // we need to announce ourselves first
}
return NULL;
}
- ver = Http::ProtocolVersion(1, 1);
+ ver = Http::ProtocolVersion(Ftp::ProtocolVersion().major, Ftp::ProtocolVersion().minor);
request->flags.ftpNative = true;
request->http_ver = ver;