1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/protocol/http/nsHttpRequestHead.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,101 @@ 1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#ifndef nsHttpRequestHead_h__ 1.10 +#define nsHttpRequestHead_h__ 1.11 + 1.12 +#include "nsHttp.h" 1.13 +#include "nsHttpHeaderArray.h" 1.14 +#include "nsString.h" 1.15 + 1.16 +namespace mozilla { namespace net { 1.17 + 1.18 +//----------------------------------------------------------------------------- 1.19 +// nsHttpRequestHead represents the request line and headers from an HTTP 1.20 +// request. 1.21 +//----------------------------------------------------------------------------- 1.22 + 1.23 +class nsHttpRequestHead 1.24 +{ 1.25 +public: 1.26 + nsHttpRequestHead(); 1.27 + 1.28 + void SetMethod(const nsACString &method); 1.29 + void SetVersion(nsHttpVersion version) { mVersion = version; } 1.30 + void SetRequestURI(const nsCSubstring &s) { mRequestURI = s; } 1.31 + 1.32 + const nsHttpHeaderArray &Headers() const { return mHeaders; } 1.33 + nsHttpHeaderArray & Headers() { return mHeaders; } 1.34 + const nsCString &Method() const { return mMethod; } 1.35 + nsHttpVersion Version() const { return mVersion; } 1.36 + const nsCSubstring &RequestURI() const { return mRequestURI; } 1.37 + 1.38 + const char *PeekHeader(nsHttpAtom h) const 1.39 + { 1.40 + return mHeaders.PeekHeader(h); 1.41 + } 1.42 + nsresult SetHeader(nsHttpAtom h, const nsACString &v, bool m=false) { return mHeaders.SetHeader(h, v, m); } 1.43 + nsresult GetHeader(nsHttpAtom h, nsACString &v) const 1.44 + { 1.45 + return mHeaders.GetHeader(h, v); 1.46 + } 1.47 + void ClearHeader(nsHttpAtom h) { mHeaders.ClearHeader(h); } 1.48 + void ClearHeaders() { mHeaders.Clear(); } 1.49 + 1.50 + const char *FindHeaderValue(nsHttpAtom h, const char *v) const 1.51 + { 1.52 + return mHeaders.FindHeaderValue(h, v); 1.53 + } 1.54 + bool HasHeaderValue(nsHttpAtom h, const char *v) const 1.55 + { 1.56 + return mHeaders.HasHeaderValue(h, v); 1.57 + } 1.58 + 1.59 + void Flatten(nsACString &, bool pruneProxyHeaders = false); 1.60 + 1.61 + // Don't allow duplicate values 1.62 + nsresult SetHeaderOnce(nsHttpAtom h, const char *v, bool merge = false) 1.63 + { 1.64 + if (!merge || !HasHeaderValue(h, v)) 1.65 + return mHeaders.SetHeader(h, nsDependentCString(v), merge); 1.66 + return NS_OK; 1.67 + } 1.68 + 1.69 + bool IsSafeMethod() const; 1.70 + 1.71 + enum ParsedMethodType 1.72 + { 1.73 + kMethod_Custom, 1.74 + kMethod_Get, 1.75 + kMethod_Post, 1.76 + kMethod_Options, 1.77 + kMethod_Connect, 1.78 + kMethod_Head, 1.79 + kMethod_Put, 1.80 + kMethod_Trace 1.81 + }; 1.82 + 1.83 + ParsedMethodType ParsedMethod() const { return mParsedMethod; } 1.84 + bool EqualsMethod(ParsedMethodType aType) const { return mParsedMethod == aType; } 1.85 + bool IsGet() const { return EqualsMethod(kMethod_Get); } 1.86 + bool IsPost() const { return EqualsMethod(kMethod_Post); } 1.87 + bool IsOptions() const { return EqualsMethod(kMethod_Options); } 1.88 + bool IsConnect() const { return EqualsMethod(kMethod_Connect); } 1.89 + bool IsHead() const { return EqualsMethod(kMethod_Head); } 1.90 + bool IsPut() const { return EqualsMethod(kMethod_Put); } 1.91 + bool IsTrace() const { return EqualsMethod(kMethod_Trace); } 1.92 + 1.93 +private: 1.94 + // All members must be copy-constructable and assignable 1.95 + nsHttpHeaderArray mHeaders; 1.96 + nsCString mMethod; 1.97 + nsHttpVersion mVersion; 1.98 + nsCString mRequestURI; 1.99 + ParsedMethodType mParsedMethod; 1.100 +}; 1.101 + 1.102 +}} // namespace mozilla::net 1.103 + 1.104 +#endif // nsHttpRequestHead_h__