netwerk/protocol/http/nsHttpRequestHead.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial