netwerk/protocol/http/nsHttpRequestHead.h

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.)

     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 #ifndef nsHttpRequestHead_h__
     7 #define nsHttpRequestHead_h__
     9 #include "nsHttp.h"
    10 #include "nsHttpHeaderArray.h"
    11 #include "nsString.h"
    13 namespace mozilla { namespace net {
    15 //-----------------------------------------------------------------------------
    16 // nsHttpRequestHead represents the request line and headers from an HTTP
    17 // request.
    18 //-----------------------------------------------------------------------------
    20 class nsHttpRequestHead
    21 {
    22 public:
    23     nsHttpRequestHead();
    25     void SetMethod(const nsACString &method);
    26     void SetVersion(nsHttpVersion version) { mVersion = version; }
    27     void SetRequestURI(const nsCSubstring &s) { mRequestURI = s; }
    29     const nsHttpHeaderArray &Headers() const { return mHeaders; }
    30     nsHttpHeaderArray & Headers()          { return mHeaders; }
    31     const nsCString &Method()        const { return mMethod; }
    32     nsHttpVersion       Version()    const { return mVersion; }
    33     const nsCSubstring &RequestURI() const { return mRequestURI; }
    35     const char *PeekHeader(nsHttpAtom h) const
    36     {
    37         return mHeaders.PeekHeader(h);
    38     }
    39     nsresult SetHeader(nsHttpAtom h, const nsACString &v, bool m=false) { return mHeaders.SetHeader(h, v, m); }
    40     nsresult GetHeader(nsHttpAtom h, nsACString &v) const
    41     {
    42         return mHeaders.GetHeader(h, v);
    43     }
    44     void ClearHeader(nsHttpAtom h)                                           { mHeaders.ClearHeader(h); }
    45     void ClearHeaders()                                                      { mHeaders.Clear(); }
    47     const char *FindHeaderValue(nsHttpAtom h, const char *v) const
    48     {
    49         return mHeaders.FindHeaderValue(h, v);
    50     }
    51     bool HasHeaderValue(nsHttpAtom h, const char *v) const
    52     {
    53       return mHeaders.HasHeaderValue(h, v);
    54     }
    56     void Flatten(nsACString &, bool pruneProxyHeaders = false);
    58     // Don't allow duplicate values
    59     nsresult SetHeaderOnce(nsHttpAtom h, const char *v, bool merge = false)
    60     {
    61         if (!merge || !HasHeaderValue(h, v))
    62             return mHeaders.SetHeader(h, nsDependentCString(v), merge);
    63         return NS_OK;
    64     }
    66     bool IsSafeMethod() const;
    68     enum ParsedMethodType
    69     {
    70         kMethod_Custom,
    71         kMethod_Get,
    72         kMethod_Post,
    73         kMethod_Options,
    74         kMethod_Connect,
    75         kMethod_Head,
    76         kMethod_Put,
    77         kMethod_Trace
    78     };
    80     ParsedMethodType ParsedMethod() const { return mParsedMethod; }
    81     bool EqualsMethod(ParsedMethodType aType) const { return mParsedMethod == aType; }
    82     bool IsGet() const { return EqualsMethod(kMethod_Get); }
    83     bool IsPost() const { return EqualsMethod(kMethod_Post); }
    84     bool IsOptions() const { return EqualsMethod(kMethod_Options); }
    85     bool IsConnect() const { return EqualsMethod(kMethod_Connect); }
    86     bool IsHead() const { return EqualsMethod(kMethod_Head); }
    87     bool IsPut() const { return EqualsMethod(kMethod_Put); }
    88     bool IsTrace() const { return EqualsMethod(kMethod_Trace); }
    90 private:
    91     // All members must be copy-constructable and assignable
    92     nsHttpHeaderArray mHeaders;
    93     nsCString         mMethod;
    94     nsHttpVersion     mVersion;
    95     nsCString         mRequestURI;
    96     ParsedMethodType  mParsedMethod;
    97 };
    99 }} // namespace mozilla::net
   101 #endif // nsHttpRequestHead_h__

mercurial