netwerk/protocol/http/nsHttpRequestHead.cpp

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)

michael@0 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 // HttpLog.h should generally be included first
michael@0 7 #include "HttpLog.h"
michael@0 8
michael@0 9 #include "nsHttpRequestHead.h"
michael@0 10
michael@0 11 //-----------------------------------------------------------------------------
michael@0 12 // nsHttpRequestHead
michael@0 13 //-----------------------------------------------------------------------------
michael@0 14
michael@0 15 namespace mozilla {
michael@0 16 namespace net {
michael@0 17
michael@0 18 nsHttpRequestHead::nsHttpRequestHead()
michael@0 19 : mMethod(NS_LITERAL_CSTRING("GET"))
michael@0 20 , mVersion(NS_HTTP_VERSION_1_1)
michael@0 21 , mParsedMethod(kMethod_Get)
michael@0 22 {
michael@0 23 }
michael@0 24
michael@0 25 void
michael@0 26 nsHttpRequestHead::SetMethod(const nsACString &method)
michael@0 27 {
michael@0 28 mParsedMethod = kMethod_Custom;
michael@0 29 mMethod = method;
michael@0 30 if (!strcmp(mMethod.get(), "GET")) {
michael@0 31 mParsedMethod = kMethod_Get;
michael@0 32 } else if (!strcmp(mMethod.get(), "POST")) {
michael@0 33 mParsedMethod = kMethod_Post;
michael@0 34 } else if (!strcmp(mMethod.get(), "OPTIONS")) {
michael@0 35 mParsedMethod = kMethod_Options;
michael@0 36 } else if (!strcmp(mMethod.get(), "CONNECT")) {
michael@0 37 mParsedMethod = kMethod_Connect;
michael@0 38 } else if (!strcmp(mMethod.get(), "HEAD")) {
michael@0 39 mParsedMethod = kMethod_Head;
michael@0 40 } else if (!strcmp(mMethod.get(), "PUT")) {
michael@0 41 mParsedMethod = kMethod_Put;
michael@0 42 } else if (!strcmp(mMethod.get(), "TRACE")) {
michael@0 43 mParsedMethod = kMethod_Trace;
michael@0 44 }
michael@0 45 }
michael@0 46
michael@0 47 bool
michael@0 48 nsHttpRequestHead::IsSafeMethod() const
michael@0 49 {
michael@0 50 // This code will need to be extended for new safe methods, otherwise
michael@0 51 // they'll default to "not safe".
michael@0 52 if (IsGet() || IsHead() || IsOptions() || IsTrace()) {
michael@0 53 return true;
michael@0 54 }
michael@0 55
michael@0 56 if (mParsedMethod != kMethod_Custom) {
michael@0 57 return false;
michael@0 58 }
michael@0 59
michael@0 60 return (!strcmp(mMethod.get(), "PROPFIND") ||
michael@0 61 !strcmp(mMethod.get(), "REPORT") ||
michael@0 62 !strcmp(mMethod.get(), "SEARCH"));
michael@0 63 }
michael@0 64
michael@0 65 void
michael@0 66 nsHttpRequestHead::Flatten(nsACString &buf, bool pruneProxyHeaders)
michael@0 67 {
michael@0 68 // note: the first append is intentional.
michael@0 69
michael@0 70 buf.Append(mMethod);
michael@0 71 buf.Append(' ');
michael@0 72 buf.Append(mRequestURI);
michael@0 73 buf.AppendLiteral(" HTTP/");
michael@0 74
michael@0 75 switch (mVersion) {
michael@0 76 case NS_HTTP_VERSION_1_1:
michael@0 77 buf.AppendLiteral("1.1");
michael@0 78 break;
michael@0 79 case NS_HTTP_VERSION_0_9:
michael@0 80 buf.AppendLiteral("0.9");
michael@0 81 break;
michael@0 82 default:
michael@0 83 buf.AppendLiteral("1.0");
michael@0 84 }
michael@0 85
michael@0 86 buf.AppendLiteral("\r\n");
michael@0 87
michael@0 88 mHeaders.Flatten(buf, pruneProxyHeaders);
michael@0 89 }
michael@0 90
michael@0 91 } // namespace mozilla::net
michael@0 92 } // namespace mozilla

mercurial