michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // HttpLog.h should generally be included first michael@0: #include "HttpLog.h" michael@0: michael@0: #include "nsHttpRequestHead.h" michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: // nsHttpRequestHead michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: namespace mozilla { michael@0: namespace net { michael@0: michael@0: nsHttpRequestHead::nsHttpRequestHead() michael@0: : mMethod(NS_LITERAL_CSTRING("GET")) michael@0: , mVersion(NS_HTTP_VERSION_1_1) michael@0: , mParsedMethod(kMethod_Get) michael@0: { michael@0: } michael@0: michael@0: void michael@0: nsHttpRequestHead::SetMethod(const nsACString &method) michael@0: { michael@0: mParsedMethod = kMethod_Custom; michael@0: mMethod = method; michael@0: if (!strcmp(mMethod.get(), "GET")) { michael@0: mParsedMethod = kMethod_Get; michael@0: } else if (!strcmp(mMethod.get(), "POST")) { michael@0: mParsedMethod = kMethod_Post; michael@0: } else if (!strcmp(mMethod.get(), "OPTIONS")) { michael@0: mParsedMethod = kMethod_Options; michael@0: } else if (!strcmp(mMethod.get(), "CONNECT")) { michael@0: mParsedMethod = kMethod_Connect; michael@0: } else if (!strcmp(mMethod.get(), "HEAD")) { michael@0: mParsedMethod = kMethod_Head; michael@0: } else if (!strcmp(mMethod.get(), "PUT")) { michael@0: mParsedMethod = kMethod_Put; michael@0: } else if (!strcmp(mMethod.get(), "TRACE")) { michael@0: mParsedMethod = kMethod_Trace; michael@0: } michael@0: } michael@0: michael@0: bool michael@0: nsHttpRequestHead::IsSafeMethod() const michael@0: { michael@0: // This code will need to be extended for new safe methods, otherwise michael@0: // they'll default to "not safe". michael@0: if (IsGet() || IsHead() || IsOptions() || IsTrace()) { michael@0: return true; michael@0: } michael@0: michael@0: if (mParsedMethod != kMethod_Custom) { michael@0: return false; michael@0: } michael@0: michael@0: return (!strcmp(mMethod.get(), "PROPFIND") || michael@0: !strcmp(mMethod.get(), "REPORT") || michael@0: !strcmp(mMethod.get(), "SEARCH")); michael@0: } michael@0: michael@0: void michael@0: nsHttpRequestHead::Flatten(nsACString &buf, bool pruneProxyHeaders) michael@0: { michael@0: // note: the first append is intentional. michael@0: michael@0: buf.Append(mMethod); michael@0: buf.Append(' '); michael@0: buf.Append(mRequestURI); michael@0: buf.AppendLiteral(" HTTP/"); michael@0: michael@0: switch (mVersion) { michael@0: case NS_HTTP_VERSION_1_1: michael@0: buf.AppendLiteral("1.1"); michael@0: break; michael@0: case NS_HTTP_VERSION_0_9: michael@0: buf.AppendLiteral("0.9"); michael@0: break; michael@0: default: michael@0: buf.AppendLiteral("1.0"); michael@0: } michael@0: michael@0: buf.AppendLiteral("\r\n"); michael@0: michael@0: mHeaders.Flatten(buf, pruneProxyHeaders); michael@0: } michael@0: michael@0: } // namespace mozilla::net michael@0: } // namespace mozilla