2001-05-12 01:04:09 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2005-04-01 22:35:14 +04:00
|
|
|
/* vim:set ts=4 sw=4 sts=4 et cin: */
|
2012-05-21 15:12:37 +04: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-12 01:04:09 +04:00
|
|
|
|
|
|
|
#ifndef nsHttp_h__
|
|
|
|
#define nsHttp_h__
|
|
|
|
|
2013-09-23 07:35:52 +04:00
|
|
|
#include <stdint.h>
|
2001-05-12 01:04:09 +04:00
|
|
|
#include "prtime.h"
|
2014-04-16 01:06:59 +04:00
|
|
|
#include "nsAutoPtr.h"
|
2013-09-23 07:35:52 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsError.h"
|
2014-08-21 18:50:17 +04:00
|
|
|
#include "nsTArray.h"
|
2017-12-03 02:13:43 +03:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2015-11-09 05:28:05 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2001-09-29 02:23:26 +04:00
|
|
|
|
2017-06-28 20:34:55 +03:00
|
|
|
class nsICacheEntry;
|
|
|
|
|
2013-07-08 17:10:18 +04:00
|
|
|
namespace mozilla {
|
2013-09-23 07:35:52 +04:00
|
|
|
|
|
|
|
class Mutex;
|
|
|
|
|
2013-07-08 17:10:18 +04:00
|
|
|
namespace net {
|
2017-06-28 20:34:55 +03:00
|
|
|
class nsHttpResponseHead;
|
|
|
|
class nsHttpRequestHead;
|
|
|
|
class CacheControlParser;
|
|
|
|
|
2018-06-01 21:32:05 +03:00
|
|
|
enum class HttpVersion {
|
|
|
|
UNKNOWN = 0,
|
|
|
|
v0_9 = 9,
|
|
|
|
v1_0 = 10,
|
|
|
|
v1_1 = 11,
|
|
|
|
v2_0 = 20
|
|
|
|
};
|
|
|
|
|
|
|
|
enum class SpdyVersion {
|
|
|
|
NONE = 0,
|
2014-11-17 20:35:06 +03:00
|
|
|
// SPDY_VERSION_2 = 2, REMOVED
|
|
|
|
// SPDY_VERSION_3 = 3, REMOVED
|
2016-07-16 01:13:49 +03:00
|
|
|
// SPDY_VERSION_31 = 4, REMOVED
|
2018-06-01 21:32:05 +03:00
|
|
|
HTTP_2 = 5
|
2013-10-10 04:21:49 +04:00
|
|
|
|
|
|
|
// leave room for official versions. telem goes to 48
|
|
|
|
// 24 was a internal spdy/3.1
|
|
|
|
// 25 was spdy/4a2
|
2014-01-14 05:16:26 +04:00
|
|
|
// 26 was http/2-draft08 and http/2-draft07 (they were the same)
|
2014-04-30 05:46:03 +04:00
|
|
|
// 27 was http/2-draft09, h2-10, and h2-11
|
2014-06-26 04:33:15 +04:00
|
|
|
// 28 was http/2-draft12
|
2014-08-05 19:41:09 +04:00
|
|
|
// 29 was http/2-draft13
|
2015-05-12 20:45:15 +03:00
|
|
|
// 30 was h2-14 and h2-15
|
|
|
|
// 31 was h2-16
|
2013-07-08 17:10:18 +04:00
|
|
|
};
|
|
|
|
|
2003-03-26 08:05:49 +03:00
|
|
|
//-----------------------------------------------------------------------------
|
2001-08-14 05:03:27 +04:00
|
|
|
// http connection capabilities
|
2003-03-26 08:05:49 +03:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
#define NS_HTTP_ALLOW_KEEPALIVE (1<<0)
|
2018-02-01 12:20:49 +03:00
|
|
|
#define NS_HTTP_LARGE_KEEPALIVE (1<<1)
|
2003-03-26 08:05:49 +03:00
|
|
|
|
|
|
|
// a transaction with this caps flag will continue to own the connection,
|
|
|
|
// preventing it from being reclaimed, even after the transaction completes.
|
|
|
|
#define NS_HTTP_STICKY_CONNECTION (1<<2)
|
|
|
|
|
2008-11-04 19:05:46 +03:00
|
|
|
// a transaction with this caps flag will, upon opening a new connection,
|
|
|
|
// bypass the local DNS cache
|
|
|
|
#define NS_HTTP_REFRESH_DNS (1<<3)
|
|
|
|
|
2009-02-18 01:06:52 +03:00
|
|
|
// a transaction with this caps flag will not pass SSL client-certificates
|
|
|
|
// to the server (see bug #466080), but is may also be used for other things
|
|
|
|
#define NS_HTTP_LOAD_ANONYMOUS (1<<4)
|
|
|
|
|
2011-05-21 14:03:36 +04:00
|
|
|
// a transaction with this caps flag keeps timing information
|
|
|
|
#define NS_HTTP_TIMING_ENABLED (1<<5)
|
|
|
|
|
2012-12-05 03:06:29 +04:00
|
|
|
// a transaction with this flag blocks the initiation of other transactons
|
|
|
|
// in the same load group until it is complete
|
|
|
|
#define NS_HTTP_LOAD_AS_BLOCKING (1<<6)
|
2011-07-22 20:31:37 +04:00
|
|
|
|
2011-12-13 19:55:50 +04:00
|
|
|
// Disallow the use of the SPDY protocol. This is meant for the contexts
|
|
|
|
// such as HTTP upgrade which are nonsensical for SPDY, it is not the
|
|
|
|
// SPDY configuration variable.
|
|
|
|
#define NS_HTTP_DISALLOW_SPDY (1<<7)
|
|
|
|
|
2012-12-05 03:06:29 +04:00
|
|
|
// a transaction with this flag loads without respect to whether the load
|
|
|
|
// group is currently blocking on some resources
|
|
|
|
#define NS_HTTP_LOAD_UNBLOCKED (1<<8)
|
|
|
|
|
2014-10-21 22:35:41 +04:00
|
|
|
// This flag indicates the transaction should accept associated pushes
|
2014-12-17 23:58:49 +03:00
|
|
|
#define NS_HTTP_ONPUSH_LISTENER (1<<9)
|
2014-10-21 22:35:41 +04:00
|
|
|
|
2016-08-16 22:51:18 +03:00
|
|
|
// Transactions with this flag should react to errors without side effects
|
|
|
|
// First user is to prevent clearing of alt-svc cache on failed probe
|
|
|
|
#define NS_HTTP_ERROR_SOFTLY (1<<10)
|
|
|
|
|
2016-12-03 00:49:23 +03:00
|
|
|
// This corresponds to nsIHttpChannelInternal.beConservative
|
|
|
|
// it disables any cutting edge features that we are worried might result in
|
|
|
|
// interop problems with critical infrastructure
|
|
|
|
#define NS_HTTP_BE_CONSERVATIVE (1<<11)
|
|
|
|
|
2017-03-11 20:31:13 +03:00
|
|
|
// Transactions with this flag should be processed first.
|
|
|
|
#define NS_HTTP_URGENT_START (1<<12)
|
|
|
|
|
2017-04-26 18:02:05 +03:00
|
|
|
// A sticky connection of the transaction is explicitly allowed to be restarted
|
|
|
|
// on ERROR_NET_RESET.
|
|
|
|
#define NS_HTTP_CONNECTION_RESTARTABLE (1<<13)
|
|
|
|
|
2018-07-13 00:48:54 +03:00
|
|
|
// Disallow name resolutions for this transaction to use TRR - primarily
|
|
|
|
// for use with TRR implementations themselves
|
|
|
|
#define NS_HTTP_DISABLE_TRR (1<<14)
|
|
|
|
|
2003-03-26 08:05:49 +03:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// some default values
|
|
|
|
//-----------------------------------------------------------------------------
|
2001-05-12 01:04:09 +04:00
|
|
|
|
2003-03-01 05:18:05 +03:00
|
|
|
#define NS_HTTP_DEFAULT_PORT 80
|
|
|
|
#define NS_HTTPS_DEFAULT_PORT 443
|
|
|
|
|
2003-05-13 08:38:25 +04:00
|
|
|
#define NS_HTTP_HEADER_SEPS ", \t"
|
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// http atoms...
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
struct nsHttpAtom
|
|
|
|
{
|
2006-02-18 01:52:40 +03:00
|
|
|
operator const char *() const { return _val; }
|
|
|
|
const char *get() const { return _val; }
|
2001-05-12 01:04:09 +04:00
|
|
|
|
2001-09-27 03:30:28 +04:00
|
|
|
void operator=(const char *v) { _val = v; }
|
|
|
|
void operator=(const nsHttpAtom &a) { _val = a._val; }
|
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
// private
|
|
|
|
const char *_val;
|
|
|
|
};
|
|
|
|
|
2017-06-28 20:34:55 +03:00
|
|
|
namespace nsHttp
|
2001-05-12 01:04:09 +04:00
|
|
|
{
|
2017-06-28 20:34:55 +03:00
|
|
|
MOZ_MUST_USE nsresult CreateAtomTable();
|
|
|
|
void DestroyAtomTable();
|
2001-05-12 01:04:09 +04:00
|
|
|
|
2012-03-23 03:39:31 +04:00
|
|
|
// The mutex is valid any time the Atom Table is valid
|
|
|
|
// This mutex is used in the unusual case that the network thread and
|
|
|
|
// main thread might access the same data
|
2017-06-28 20:34:55 +03:00
|
|
|
Mutex *GetLock();
|
2012-03-23 03:39:31 +04:00
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
// will dynamically add atoms to the table if they don't already exist
|
2017-06-28 20:34:55 +03:00
|
|
|
nsHttpAtom ResolveAtom(const char *);
|
|
|
|
inline nsHttpAtom ResolveAtom(const nsACString &s)
|
2005-04-01 22:35:14 +04:00
|
|
|
{
|
|
|
|
return ResolveAtom(PromiseFlatCString(s).get());
|
|
|
|
}
|
2001-05-12 01:04:09 +04:00
|
|
|
|
2006-04-07 21:45:44 +04:00
|
|
|
// returns true if the specified token [start,end) is valid per RFC 2616
|
|
|
|
// section 2.2
|
2017-06-28 20:34:55 +03:00
|
|
|
bool IsValidToken(const char *start, const char *end);
|
2006-04-07 21:45:44 +04:00
|
|
|
|
2017-06-28 20:34:55 +03:00
|
|
|
inline bool IsValidToken(const nsACString &s) {
|
2014-07-24 20:38:55 +04:00
|
|
|
return IsValidToken(s.BeginReading(), s.EndReading());
|
2006-04-07 21:45:44 +04:00
|
|
|
}
|
|
|
|
|
2017-04-10 11:15:29 +03:00
|
|
|
// Strip the leading or trailing HTTP whitespace per fetch spec section 2.2.
|
2017-06-28 20:34:55 +03:00
|
|
|
void TrimHTTPWhitespace(const nsACString& aSource,
|
2017-04-10 11:15:29 +03:00
|
|
|
nsACString& aDest);
|
|
|
|
|
2014-07-24 20:38:55 +04:00
|
|
|
// Returns true if the specified value is reasonable given the defintion
|
|
|
|
// in RFC 2616 section 4.2. Full strict validation is not performed
|
|
|
|
// currently as it would require full parsing of the value.
|
2017-06-28 20:34:55 +03:00
|
|
|
bool IsReasonableHeaderValue(const nsACString &s);
|
2014-07-24 20:38:55 +04:00
|
|
|
|
2006-02-18 01:52:40 +03:00
|
|
|
// find the first instance (case-insensitive comparison) of the given
|
|
|
|
// |token| in the |input| string. the |token| is bounded by elements of
|
|
|
|
// |separators| and may appear at the beginning or end of the |input|
|
|
|
|
// string. null is returned if the |token| is not found. |input| may be
|
|
|
|
// null, in which case null is returned.
|
2017-06-28 20:34:55 +03:00
|
|
|
const char *FindToken(const char *input, const char *token,
|
2006-02-18 01:52:40 +03:00
|
|
|
const char *separators);
|
|
|
|
|
2006-04-07 21:44:32 +04:00
|
|
|
// This function parses a string containing a decimal-valued, non-negative
|
2012-09-28 23:55:23 +04:00
|
|
|
// 64-bit integer. If the value would exceed INT64_MAX, then false is
|
2011-10-17 18:59:28 +04:00
|
|
|
// returned. Otherwise, this function returns true and stores the
|
2006-04-07 21:44:32 +04:00
|
|
|
// parsed value in |result|. The next unparsed character in |input| is
|
|
|
|
// optionally returned via |next| if |next| is non-null.
|
|
|
|
//
|
|
|
|
// TODO(darin): Replace this with something generic.
|
|
|
|
//
|
2017-06-28 20:34:55 +03:00
|
|
|
MOZ_MUST_USE bool ParseInt64(const char *input, const char **next,
|
2016-12-27 10:22:07 +03:00
|
|
|
int64_t *result);
|
2006-04-07 21:44:32 +04:00
|
|
|
|
|
|
|
// Variant on ParseInt64 that expects the input string to contain nothing
|
|
|
|
// more than the value being parsed.
|
2017-06-28 20:34:55 +03:00
|
|
|
inline MOZ_MUST_USE bool ParseInt64(const char *input,
|
2016-12-27 10:22:07 +03:00
|
|
|
int64_t *result) {
|
2006-04-07 21:44:32 +04:00
|
|
|
const char *next;
|
|
|
|
return ParseInt64(input, &next, result) && *next == '\0';
|
|
|
|
}
|
|
|
|
|
2012-09-22 19:27:17 +04:00
|
|
|
// Return whether the HTTP status code represents a permanent redirect
|
2017-06-28 20:34:55 +03:00
|
|
|
bool IsPermanentRedirect(uint32_t httpStatus);
|
2012-09-22 19:27:17 +04:00
|
|
|
|
2015-07-24 18:49:25 +03:00
|
|
|
// Returns the APLN token which represents the used protocol version.
|
2018-06-01 21:32:05 +03:00
|
|
|
const char* GetProtocolVersion(HttpVersion pv);
|
2017-06-28 20:34:55 +03:00
|
|
|
|
|
|
|
bool ValidationRequired(bool isForcedValid, nsHttpResponseHead *cachedResponseHead,
|
|
|
|
uint32_t loadFlags, bool allowStaleCacheContent,
|
|
|
|
bool isImmutable, bool customConditionalRequest,
|
|
|
|
nsHttpRequestHead &requestHead,
|
|
|
|
nsICacheEntry *entry, CacheControlParser &cacheControlRequest,
|
|
|
|
bool fromPreviousSession);
|
|
|
|
|
|
|
|
nsresult GetHttpResponseHeadFromCacheEntry(nsICacheEntry *entry,
|
|
|
|
nsHttpResponseHead *cachedResponseHead);
|
|
|
|
|
|
|
|
nsresult CheckPartial(nsICacheEntry* aEntry, int64_t *aSize,
|
|
|
|
int64_t *aContentLength,
|
|
|
|
nsHttpResponseHead *responseHead);
|
|
|
|
|
|
|
|
void DetermineFramingAndImmutability(nsICacheEntry *entry, nsHttpResponseHead *cachedResponseHead,
|
|
|
|
bool isHttps, bool *weaklyFramed,
|
|
|
|
bool *isImmutable);
|
2015-07-24 18:49:25 +03:00
|
|
|
|
2017-12-03 02:13:43 +03:00
|
|
|
// Called when an optimization feature affecting active vs background tab load
|
|
|
|
// took place. Called only on the parent process and only updates
|
|
|
|
// mLastActiveTabLoadOptimizationHit timestamp to now.
|
|
|
|
void NotifyActiveTabLoadOptimization();
|
|
|
|
TimeStamp const GetLastActiveTabLoadOptimizationHit();
|
|
|
|
void SetLastActiveTabLoadOptimizationHit(TimeStamp const &when);
|
|
|
|
bool IsBeforeLastActiveTabLoadOptimization(TimeStamp const &when);
|
|
|
|
|
2018-06-01 21:32:05 +03:00
|
|
|
HttpVersion GetHttpVersionFromSpdy(SpdyVersion sv);
|
|
|
|
|
2006-02-18 01:52:40 +03:00
|
|
|
// Declare all atoms
|
2012-08-28 05:21:20 +04:00
|
|
|
//
|
2006-02-18 01:52:40 +03:00
|
|
|
// The atom names and values are stored in nsHttpAtomList.h and are brought
|
|
|
|
// to you by the magic of C preprocessing. Add new atoms to nsHttpAtomList
|
|
|
|
// and all support logic will be auto-generated.
|
|
|
|
//
|
2017-06-28 20:34:55 +03:00
|
|
|
#define HTTP_ATOM(_name, _value) extern nsHttpAtom _name;
|
2001-05-12 01:04:09 +04:00
|
|
|
#include "nsHttpAtomList.h"
|
|
|
|
#undef HTTP_ATOM
|
2017-06-28 20:34:55 +03:00
|
|
|
}
|
2001-05-12 01:04:09 +04:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// utilities...
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static inline uint32_t
|
2001-05-12 01:04:09 +04:00
|
|
|
PRTimeToSeconds(PRTime t_usec)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
return uint32_t( t_usec / PR_USEC_PER_SEC );
|
2001-05-12 01:04:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#define NowInSeconds() PRTimeToSeconds(PR_Now())
|
|
|
|
|
2012-08-30 06:49:31 +04:00
|
|
|
// Round q-value to 2 decimal places; return 2 most significant digits as uint.
|
|
|
|
#define QVAL_TO_UINT(q) ((unsigned int) ((q + 0.005) * 100.0))
|
2002-11-20 23:51:12 +03:00
|
|
|
|
2003-06-19 03:16:17 +04:00
|
|
|
#define HTTP_LWS " \t"
|
2006-02-18 01:52:40 +03:00
|
|
|
#define HTTP_HEADER_VALUE_SEPS HTTP_LWS ","
|
2003-06-19 03:16:17 +04:00
|
|
|
|
2015-11-09 05:28:05 +03:00
|
|
|
void EnsureBuffer(UniquePtr<char[]> &buf, uint32_t newSize,
|
2014-04-16 01:06:59 +04:00
|
|
|
uint32_t preserve, uint32_t &objSize);
|
2015-11-09 05:28:05 +03:00
|
|
|
void EnsureBuffer(UniquePtr<uint8_t[]> &buf, uint32_t newSize,
|
2014-04-16 01:06:59 +04:00
|
|
|
uint32_t preserve, uint32_t &objSize);
|
|
|
|
|
2014-08-21 18:50:17 +04:00
|
|
|
// h2=":443"; ma=60; single
|
|
|
|
// results in 3 mValues = {{h2, :443}, {ma, 60}, {single}}
|
|
|
|
|
|
|
|
class ParsedHeaderPair
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ParsedHeaderPair(const char *name, int32_t nameLen,
|
2018-01-03 03:04:00 +03:00
|
|
|
const char *val, int32_t valLen, bool isQuotedValue);
|
2014-08-21 18:50:17 +04:00
|
|
|
|
|
|
|
ParsedHeaderPair(ParsedHeaderPair const ©)
|
|
|
|
: mName(copy.mName)
|
|
|
|
, mValue(copy.mValue)
|
2018-01-03 03:04:00 +03:00
|
|
|
, mUnquotedValue(copy.mUnquotedValue)
|
|
|
|
, mIsQuotedValue(copy.mIsQuotedValue)
|
2014-08-21 18:50:17 +04:00
|
|
|
{
|
2018-01-03 03:04:00 +03:00
|
|
|
if (mIsQuotedValue) {
|
|
|
|
mValue.Rebind(mUnquotedValue.BeginReading(), mUnquotedValue.Length());
|
|
|
|
}
|
2014-08-21 18:50:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsDependentCSubstring mName;
|
|
|
|
nsDependentCSubstring mValue;
|
2018-01-03 03:04:00 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
nsCString mUnquotedValue;
|
|
|
|
bool mIsQuotedValue;
|
|
|
|
|
|
|
|
void RemoveQuotedStringEscapes(const char *val, int32_t valLen);
|
2014-08-21 18:50:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class ParsedHeaderValueList
|
|
|
|
{
|
|
|
|
public:
|
2018-01-03 03:04:00 +03:00
|
|
|
ParsedHeaderValueList(const char *t, uint32_t len, bool allowInvalidValue);
|
2014-08-21 18:50:17 +04:00
|
|
|
nsTArray<ParsedHeaderPair> mValues;
|
|
|
|
|
|
|
|
private:
|
2018-01-03 03:04:00 +03:00
|
|
|
void ParseNameAndValue(const char *input, bool allowInvalidValue);
|
2014-08-21 18:50:17 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class ParsedHeaderValueListList
|
|
|
|
{
|
|
|
|
public:
|
2018-01-03 03:04:00 +03:00
|
|
|
// RFC 7231 section 3.2.6 defines the syntax of the header field values.
|
|
|
|
// |allowInvalidValue| indicates whether the rule will be used to check
|
|
|
|
// the input text.
|
|
|
|
// Note that ParsedHeaderValueListList is currently used to parse
|
|
|
|
// Alt-Svc and Server-Timing header. |allowInvalidValue| is set to true
|
|
|
|
// when parsing Alt-Svc for historical reasons.
|
|
|
|
explicit ParsedHeaderValueListList(const nsCString &txt,
|
|
|
|
bool allowInvalidValue = true);
|
2014-08-21 18:50:17 +04:00
|
|
|
nsTArray<ParsedHeaderValueList> mValues;
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCString mFull;
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace net
|
2014-01-08 02:05:56 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2001-08-14 05:03:27 +04:00
|
|
|
#endif // nsHttp_h__
|