Bug 458256. Use LoadLibraryW instead of LoadLibrary (patch by DougT). r+sr=vlad
[wine-gecko.git] / netwerk / protocol / http / src / nsHttpResponseHead.h
blob890a79ddb9bf6857b62d009122c78496212d7b5c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is Mozilla.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications.
19 * Portions created by the Initial Developer are Copyright (C) 2001
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Darin Fisher <darin@netscape.com> (original author)
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef nsHttpResponseHead_h__
40 #define nsHttpResponseHead_h__
42 #include "nsHttpHeaderArray.h"
43 #include "nsHttp.h"
44 #include "nsString.h"
46 //-----------------------------------------------------------------------------
47 // nsHttpResponseHead represents the status line and headers from an HTTP
48 // response.
49 //-----------------------------------------------------------------------------
51 class nsHttpResponseHead
53 public:
54 nsHttpResponseHead() : mVersion(NS_HTTP_VERSION_1_1)
55 , mStatus(200)
56 , mContentLength(LL_MAXUINT)
57 , mCacheControlNoStore(PR_FALSE)
58 , mCacheControlNoCache(PR_FALSE)
59 , mCacheControlPublic(PR_FALSE)
60 , mPragmaNoCache(PR_FALSE) {}
61 ~nsHttpResponseHead()
63 Reset();
66 nsHttpHeaderArray &Headers() { return mHeaders; }
67 nsHttpVersion Version() { return mVersion; }
68 PRUint16 Status() { return mStatus; }
69 const nsAFlatCString &StatusText() { return mStatusText; }
70 PRInt64 ContentLength() { return mContentLength; }
71 const nsAFlatCString &ContentType() { return mContentType; }
72 const nsAFlatCString &ContentCharset() { return mContentCharset; }
73 PRBool NoStore() { return mCacheControlNoStore; }
74 PRBool NoCache() { return (mCacheControlNoCache || mPragmaNoCache); }
75 PRBool CacheControlPublic() { return mCacheControlPublic; }
76 /**
77 * Full length of the entity. For byte-range requests, this may be larger
78 * than ContentLength(), which will only represent the requested part of the
79 * entity.
81 PRInt64 TotalEntitySize();
83 const char *PeekHeader(nsHttpAtom h) { return mHeaders.PeekHeader(h); }
84 nsresult SetHeader(nsHttpAtom h, const nsACString &v, PRBool m=PR_FALSE);
85 nsresult GetHeader(nsHttpAtom h, nsACString &v) { return mHeaders.GetHeader(h, v); }
86 void ClearHeader(nsHttpAtom h) { mHeaders.ClearHeader(h); }
87 void ClearHeaders() { mHeaders.Clear(); }
89 const char *FindHeaderValue(nsHttpAtom h, const char *v) { return mHeaders.FindHeaderValue(h, v); }
90 PRBool HasHeaderValue(nsHttpAtom h, const char *v) { return mHeaders.HasHeaderValue(h, v); }
92 void SetContentType(const nsACString &s) { mContentType = s; }
93 void SetContentCharset(const nsACString &s) { mContentCharset = s; }
94 void SetContentLength(PRInt64);
96 // write out the response status line and headers as a single text block,
97 // optionally pruning out transient headers (ie. headers that only make
98 // sense the first time the response is handled).
99 void Flatten(nsACString &, PRBool pruneTransients);
101 // parse flattened response head. block must be null terminated. parsing is
102 // destructive.
103 nsresult Parse(char *block);
105 // parse the status line. line must be null terminated.
106 void ParseStatusLine(char *line);
108 // parse a header line. line must be null terminated. parsing is destructive.
109 void ParseHeaderLine(char *line);
111 // cache validation support methods
112 nsresult ComputeFreshnessLifetime(PRUint32 *);
113 nsresult ComputeCurrentAge(PRUint32 now, PRUint32 requestTime, PRUint32 *result);
114 PRBool MustValidate();
115 PRBool MustValidateIfExpired();
117 // returns true if the server appears to support byte range requests.
118 PRBool IsResumable();
120 // returns true if the Expires header has a value in the past relative to the
121 // value of the Date header.
122 PRBool ExpiresInPast();
124 // update headers...
125 nsresult UpdateHeaders(nsHttpHeaderArray &headers);
127 // reset the response head to it's initial state
128 void Reset();
130 // these return failure if the header does not exist.
131 nsresult ParseDateHeader(nsHttpAtom header, PRUint32 *result);
132 nsresult GetAgeValue(PRUint32 *result);
133 nsresult GetMaxAgeValue(PRUint32 *result);
134 nsresult GetDateValue(PRUint32 *result) { return ParseDateHeader(nsHttp::Date, result); }
135 nsresult GetExpiresValue(PRUint32 *result);
136 nsresult GetLastModifiedValue(PRUint32 *result) { return ParseDateHeader(nsHttp::Last_Modified, result); }
138 private:
139 void ParseVersion(const char *);
140 void ParseCacheControl(const char *);
141 void ParsePragma(const char *);
143 private:
144 nsHttpHeaderArray mHeaders;
145 nsHttpVersion mVersion;
146 PRUint16 mStatus;
147 nsCString mStatusText;
148 PRInt64 mContentLength;
149 nsCString mContentType;
150 nsCString mContentCharset;
151 PRPackedBool mCacheControlNoStore;
152 PRPackedBool mCacheControlNoCache;
153 PRPackedBool mCacheControlPublic;
154 PRPackedBool mPragmaNoCache;
157 #endif // nsHttpResponseHead_h__