2001-05-11 21:04:09 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
#ifndef nsHttpResponseHead_h__
|
|
|
|
#define nsHttpResponseHead_h__
|
|
|
|
|
|
|
|
#include "nsHttpHeaderArray.h"
|
|
|
|
#include "nsHttp.h"
|
2002-03-20 22:50:33 +00:00
|
|
|
#include "nsString.h"
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2014-01-07 22:05:56 +00:00
|
|
|
namespace mozilla { namespace net {
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsHttpResponseHead represents the status line and headers from an HTTP
|
|
|
|
// response.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class nsHttpResponseHead
|
|
|
|
{
|
|
|
|
public:
|
2011-07-05 06:12:32 +00:00
|
|
|
nsHttpResponseHead() : mVersion(NS_HTTP_VERSION_1_1)
|
2001-05-11 21:04:09 +00:00
|
|
|
, mStatus(200)
|
2015-01-08 19:48:52 +00:00
|
|
|
, mContentLength(-1)
|
2015-01-08 21:38:00 +00:00
|
|
|
, mCacheControlPrivate(false)
|
2011-10-17 14:59:28 +00:00
|
|
|
, mCacheControlNoStore(false)
|
|
|
|
, mCacheControlNoCache(false)
|
|
|
|
, mPragmaNoCache(false) {}
|
2013-05-16 13:30:42 +00:00
|
|
|
|
2012-04-05 08:21:02 +00:00
|
|
|
const nsHttpHeaderArray & Headers() const { return mHeaders; }
|
|
|
|
nsHttpHeaderArray &Headers() { return mHeaders; }
|
|
|
|
nsHttpVersion Version() const { return mVersion; }
|
2013-06-22 16:09:19 +00:00
|
|
|
// X11's Xlib.h #defines 'Status' to 'int' on some systems!
|
|
|
|
#undef Status
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t Status() const { return mStatus; }
|
2012-04-05 08:21:02 +00:00
|
|
|
const nsAFlatCString &StatusText() const { return mStatusText; }
|
2012-08-22 15:56:38 +00:00
|
|
|
int64_t ContentLength() const { return mContentLength; }
|
2012-04-05 08:21:02 +00:00
|
|
|
const nsAFlatCString &ContentType() const { return mContentType; }
|
|
|
|
const nsAFlatCString &ContentCharset() const { return mContentCharset; }
|
2015-01-08 21:38:00 +00:00
|
|
|
bool Private() const { return mCacheControlPrivate; }
|
2012-04-05 08:21:02 +00:00
|
|
|
bool NoStore() const { return mCacheControlNoStore; }
|
|
|
|
bool NoCache() const { return (mCacheControlNoCache || mPragmaNoCache); }
|
2004-04-14 17:37:39 +00:00
|
|
|
/**
|
|
|
|
* Full length of the entity. For byte-range requests, this may be larger
|
|
|
|
* than ContentLength(), which will only represent the requested part of the
|
|
|
|
* entity.
|
|
|
|
*/
|
2012-08-22 15:56:38 +00:00
|
|
|
int64_t TotalEntitySize() const;
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2012-04-05 08:21:02 +00:00
|
|
|
const char *PeekHeader(nsHttpAtom h) const { return mHeaders.PeekHeader(h); }
|
2011-09-29 06:19:26 +00:00
|
|
|
nsresult SetHeader(nsHttpAtom h, const nsACString &v, bool m=false);
|
2012-04-05 08:21:02 +00:00
|
|
|
nsresult GetHeader(nsHttpAtom h, nsACString &v) const { return mHeaders.GetHeader(h, v); }
|
2002-11-22 07:40:16 +00:00
|
|
|
void ClearHeader(nsHttpAtom h) { mHeaders.ClearHeader(h); }
|
2001-05-11 21:04:09 +00:00
|
|
|
void ClearHeaders() { mHeaders.Clear(); }
|
|
|
|
|
2012-04-05 08:21:02 +00:00
|
|
|
const char *FindHeaderValue(nsHttpAtom h, const char *v) const
|
|
|
|
{
|
|
|
|
return mHeaders.FindHeaderValue(h, v);
|
|
|
|
}
|
|
|
|
bool HasHeaderValue(nsHttpAtom h, const char *v) const
|
|
|
|
{
|
|
|
|
return mHeaders.HasHeaderValue(h, v);
|
|
|
|
}
|
2006-02-17 22:52:40 +00:00
|
|
|
|
2002-03-20 22:50:33 +00:00
|
|
|
void SetContentType(const nsACString &s) { mContentType = s; }
|
|
|
|
void SetContentCharset(const nsACString &s) { mContentCharset = s; }
|
2012-08-22 15:56:38 +00:00
|
|
|
void SetContentLength(int64_t);
|
2001-05-15 17:47:51 +00:00
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
// write out the response status line and headers as a single text block,
|
|
|
|
// optionally pruning out transient headers (ie. headers that only make
|
|
|
|
// sense the first time the response is handled).
|
2011-09-29 06:19:26 +00:00
|
|
|
void Flatten(nsACString &, bool pruneTransients);
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
// parse flattened response head. block must be null terminated. parsing is
|
|
|
|
// destructive.
|
|
|
|
nsresult Parse(char *block);
|
|
|
|
|
|
|
|
// parse the status line. line must be null terminated.
|
2010-05-02 00:37:00 +00:00
|
|
|
void ParseStatusLine(const char *line);
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
// parse a header line. line must be null terminated. parsing is destructive.
|
2011-05-31 23:51:51 +00:00
|
|
|
nsresult ParseHeaderLine(const char *line);
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
// cache validation support methods
|
2012-08-22 15:56:38 +00:00
|
|
|
nsresult ComputeFreshnessLifetime(uint32_t *) const;
|
|
|
|
nsresult ComputeCurrentAge(uint32_t now, uint32_t requestTime, uint32_t *result) const;
|
2012-04-05 08:21:02 +00:00
|
|
|
bool MustValidate() const;
|
|
|
|
bool MustValidateIfExpired() const;
|
2002-01-09 04:18:48 +00:00
|
|
|
|
2002-03-26 23:33:19 +00:00
|
|
|
// returns true if the server appears to support byte range requests.
|
2012-04-05 08:21:02 +00:00
|
|
|
bool IsResumable() const;
|
2002-03-26 23:33:19 +00:00
|
|
|
|
2002-01-09 04:18:48 +00:00
|
|
|
// returns true if the Expires header has a value in the past relative to the
|
|
|
|
// value of the Date header.
|
2012-04-05 08:21:02 +00:00
|
|
|
bool ExpiresInPast() const;
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
// update headers...
|
2013-05-16 13:30:42 +00:00
|
|
|
nsresult UpdateHeaders(const nsHttpHeaderArray &headers);
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
// reset the response head to it's initial state
|
|
|
|
void Reset();
|
|
|
|
|
|
|
|
// these return failure if the header does not exist.
|
2012-08-22 15:56:38 +00:00
|
|
|
nsresult ParseDateHeader(nsHttpAtom header, uint32_t *result) const;
|
|
|
|
nsresult GetAgeValue(uint32_t *result) const;
|
|
|
|
nsresult GetMaxAgeValue(uint32_t *result) const;
|
|
|
|
nsresult GetDateValue(uint32_t *result) const
|
2012-04-05 08:21:02 +00:00
|
|
|
{
|
|
|
|
return ParseDateHeader(nsHttp::Date, result);
|
|
|
|
}
|
2012-08-22 15:56:38 +00:00
|
|
|
nsresult GetExpiresValue(uint32_t *result) const ;
|
|
|
|
nsresult GetLastModifiedValue(uint32_t *result) const
|
2012-04-05 08:21:02 +00:00
|
|
|
{
|
|
|
|
return ParseDateHeader(nsHttp::Last_Modified, result);
|
|
|
|
}
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2001-06-13 01:10:17 +00:00
|
|
|
private:
|
2013-12-17 15:21:39 +00:00
|
|
|
void AssignDefaultStatusText();
|
2001-06-13 01:10:17 +00:00
|
|
|
void ParseVersion(const char *);
|
2002-01-09 04:18:48 +00:00
|
|
|
void ParseCacheControl(const char *);
|
|
|
|
void ParsePragma(const char *);
|
2001-06-13 01:10:17 +00:00
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
private:
|
2012-04-05 08:21:02 +00:00
|
|
|
// All members must be copy-constructable and assignable
|
2001-05-11 21:04:09 +00:00
|
|
|
nsHttpHeaderArray mHeaders;
|
|
|
|
nsHttpVersion mVersion;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint16_t mStatus;
|
2013-06-24 23:46:08 +00:00
|
|
|
nsCString mStatusText;
|
2012-08-22 15:56:38 +00:00
|
|
|
int64_t mContentLength;
|
2013-06-24 23:46:08 +00:00
|
|
|
nsCString mContentType;
|
|
|
|
nsCString mContentCharset;
|
2015-01-08 21:38:00 +00:00
|
|
|
bool mCacheControlPrivate;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mCacheControlNoStore;
|
|
|
|
bool mCacheControlNoCache;
|
|
|
|
bool mPragmaNoCache;
|
2010-03-23 15:14:36 +00:00
|
|
|
|
|
|
|
friend struct IPC::ParamTraits<nsHttpResponseHead>;
|
2001-05-11 21:04:09 +00:00
|
|
|
};
|
2014-01-07 22:05:56 +00:00
|
|
|
}} // namespace mozilla::net
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
#endif // nsHttpResponseHead_h__
|