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