2001-05-11 21:04:09 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2013-06-22 16:01:06 +00:00
|
|
|
// HttpLog.h should generally be included first
|
|
|
|
#include "HttpLog.h"
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
#include "nsHttpRequestHead.h"
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpRequestHead
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2014-01-07 22:05:56 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
2014-03-18 16:36:18 +00:00
|
|
|
nsHttpRequestHead::nsHttpRequestHead()
|
|
|
|
: mMethod(NS_LITERAL_CSTRING("GET"))
|
|
|
|
, mVersion(NS_HTTP_VERSION_1_1)
|
|
|
|
, mParsedMethod(kMethod_Get)
|
2014-04-16 13:23:20 +00:00
|
|
|
, mHTTPS(false)
|
2014-03-18 16:36:18 +00:00
|
|
|
{
|
2014-04-21 12:54:07 +00:00
|
|
|
MOZ_COUNT_CTOR(nsHttpRequestHead);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHttpRequestHead::~nsHttpRequestHead()
|
|
|
|
{
|
|
|
|
MOZ_COUNT_DTOR(nsHttpRequestHead);
|
2014-03-18 16:36:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsHttpRequestHead::SetMethod(const nsACString &method)
|
|
|
|
{
|
|
|
|
mParsedMethod = kMethod_Custom;
|
|
|
|
mMethod = method;
|
|
|
|
if (!strcmp(mMethod.get(), "GET")) {
|
|
|
|
mParsedMethod = kMethod_Get;
|
|
|
|
} else if (!strcmp(mMethod.get(), "POST")) {
|
|
|
|
mParsedMethod = kMethod_Post;
|
|
|
|
} else if (!strcmp(mMethod.get(), "OPTIONS")) {
|
|
|
|
mParsedMethod = kMethod_Options;
|
|
|
|
} else if (!strcmp(mMethod.get(), "CONNECT")) {
|
|
|
|
mParsedMethod = kMethod_Connect;
|
|
|
|
} else if (!strcmp(mMethod.get(), "HEAD")) {
|
|
|
|
mParsedMethod = kMethod_Head;
|
|
|
|
} else if (!strcmp(mMethod.get(), "PUT")) {
|
|
|
|
mParsedMethod = kMethod_Put;
|
|
|
|
} else if (!strcmp(mMethod.get(), "TRACE")) {
|
|
|
|
mParsedMethod = kMethod_Trace;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-21 14:50:17 +00:00
|
|
|
void
|
|
|
|
nsHttpRequestHead::SetOrigin(const nsACString &scheme, const nsACString &host, int32_t port)
|
|
|
|
{
|
|
|
|
mOrigin.Assign(scheme);
|
|
|
|
mOrigin.Append(NS_LITERAL_CSTRING("://"));
|
|
|
|
mOrigin.Append(host);
|
|
|
|
if (port >= 0) {
|
|
|
|
mOrigin.Append(NS_LITERAL_CSTRING(":"));
|
|
|
|
mOrigin.AppendInt(port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-18 16:36:18 +00:00
|
|
|
bool
|
|
|
|
nsHttpRequestHead::IsSafeMethod() const
|
|
|
|
{
|
|
|
|
// This code will need to be extended for new safe methods, otherwise
|
|
|
|
// they'll default to "not safe".
|
|
|
|
if (IsGet() || IsHead() || IsOptions() || IsTrace()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mParsedMethod != kMethod_Custom) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (!strcmp(mMethod.get(), "PROPFIND") ||
|
|
|
|
!strcmp(mMethod.get(), "REPORT") ||
|
|
|
|
!strcmp(mMethod.get(), "SEARCH"));
|
|
|
|
}
|
|
|
|
|
2001-05-16 23:58:06 +00:00
|
|
|
void
|
2011-09-29 06:19:26 +00:00
|
|
|
nsHttpRequestHead::Flatten(nsACString &buf, bool pruneProxyHeaders)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
|
|
|
// note: the first append is intentional.
|
2013-05-16 13:30:42 +00:00
|
|
|
|
2014-03-18 16:36:18 +00:00
|
|
|
buf.Append(mMethod);
|
2001-05-11 21:04:09 +00:00
|
|
|
buf.Append(' ');
|
|
|
|
buf.Append(mRequestURI);
|
2004-12-04 10:19:29 +00:00
|
|
|
buf.AppendLiteral(" HTTP/");
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
switch (mVersion) {
|
|
|
|
case NS_HTTP_VERSION_1_1:
|
2004-12-04 10:19:29 +00:00
|
|
|
buf.AppendLiteral("1.1");
|
2001-05-11 21:04:09 +00:00
|
|
|
break;
|
|
|
|
case NS_HTTP_VERSION_0_9:
|
2004-12-04 10:19:29 +00:00
|
|
|
buf.AppendLiteral("0.9");
|
2001-05-11 21:04:09 +00:00
|
|
|
break;
|
|
|
|
default:
|
2004-12-04 10:19:29 +00:00
|
|
|
buf.AppendLiteral("1.0");
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
2004-12-04 10:19:29 +00:00
|
|
|
buf.AppendLiteral("\r\n");
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2002-03-13 07:34:51 +00:00
|
|
|
mHeaders.Flatten(buf, pruneProxyHeaders);
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
2014-01-07 22:05:56 +00:00
|
|
|
|
2015-07-13 15:25:42 +00:00
|
|
|
} // namespace net
|
2014-01-07 22:05:56 +00:00
|
|
|
} // namespace mozilla
|