2001-05-11 21:04:09 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2005-04-01 18:35:14 +00:00
|
|
|
/* vim:set ts=4 sw=4 sts=4 et cin: */
|
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 nsHttp_h__
|
|
|
|
#define nsHttp_h__
|
|
|
|
|
2013-09-23 03:35:52 +00:00
|
|
|
#include <stdint.h>
|
2001-05-11 21:04:09 +00:00
|
|
|
#include "prtime.h"
|
2014-04-15 21:06:59 +00:00
|
|
|
#include "nsAutoPtr.h"
|
2013-09-23 03:35:52 +00:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsError.h"
|
2014-08-21 14:50:17 +00:00
|
|
|
#include "nsTArray.h"
|
2001-09-28 22:23:26 +00:00
|
|
|
|
2001-08-14 01:03:27 +00:00
|
|
|
// http version codes
|
|
|
|
#define NS_HTTP_VERSION_UNKNOWN 0
|
|
|
|
#define NS_HTTP_VERSION_0_9 9
|
|
|
|
#define NS_HTTP_VERSION_1_0 10
|
|
|
|
#define NS_HTTP_VERSION_1_1 11
|
2014-01-29 21:42:19 +00:00
|
|
|
#define NS_HTTP_VERSION_2_0 20
|
2001-08-14 01:03:27 +00:00
|
|
|
|
2013-07-08 13:10:18 +00:00
|
|
|
namespace mozilla {
|
2013-09-23 03:35:52 +00:00
|
|
|
|
|
|
|
class Mutex;
|
|
|
|
|
2013-07-08 13:10:18 +00:00
|
|
|
namespace net {
|
|
|
|
enum {
|
2014-11-17 17:35:06 +00:00
|
|
|
// SPDY_VERSION_2 = 2, REMOVED
|
|
|
|
// SPDY_VERSION_3 = 3, REMOVED
|
2013-10-10 00:21:49 +00:00
|
|
|
SPDY_VERSION_31 = 4,
|
2014-09-23 17:49:13 +00:00
|
|
|
HTTP_VERSION_2 = 5,
|
2013-10-10 00:21:49 +00:00
|
|
|
|
|
|
|
// leave room for official versions. telem goes to 48
|
|
|
|
// 24 was a internal spdy/3.1
|
|
|
|
// 25 was spdy/4a2
|
2014-01-14 01:16:26 +00:00
|
|
|
// 26 was http/2-draft08 and http/2-draft07 (they were the same)
|
2014-04-30 01:46:03 +00:00
|
|
|
// 27 was http/2-draft09, h2-10, and h2-11
|
2014-06-26 00:33:15 +00:00
|
|
|
// 28 was http/2-draft12
|
2014-08-05 15:41:09 +00:00
|
|
|
// 29 was http/2-draft13
|
2014-12-04 19:50:38 +00:00
|
|
|
// 30 was also h2-14 and -15. They're effectively the same, -15 added an
|
|
|
|
// error code. So, we advertise all, but our "default position" is -16.
|
|
|
|
HTTP2_VERSION_DRAFT16 = 30
|
2013-07-08 13:10:18 +00:00
|
|
|
};
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
typedef uint8_t nsHttpVersion;
|
2001-08-14 01:03:27 +00:00
|
|
|
|
2014-12-04 19:50:38 +00:00
|
|
|
#define NS_HTTP2_DRAFT_VERSION HTTP2_VERSION_DRAFT16
|
|
|
|
#define NS_HTTP2_DRAFT_TOKEN "h2-16"
|
2013-10-10 00:21:49 +00:00
|
|
|
|
2003-03-26 05:05:49 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2001-08-14 01:03:27 +00:00
|
|
|
// http connection capabilities
|
2003-03-26 05:05:49 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
#define NS_HTTP_ALLOW_KEEPALIVE (1<<0)
|
|
|
|
#define NS_HTTP_ALLOW_PIPELINING (1<<1)
|
2003-03-26 05:05:49 +00: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 16:05:46 +00: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-17 22:06:52 +00: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 10:03:36 +00:00
|
|
|
// a transaction with this caps flag keeps timing information
|
|
|
|
#define NS_HTTP_TIMING_ENABLED (1<<5)
|
|
|
|
|
2012-12-04 23:06:29 +00: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 16:31:37 +00:00
|
|
|
|
2011-12-13 15:55:50 +00: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-04 23:06:29 +00: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)
|
|
|
|
|
2013-06-28 20:58:28 +00:00
|
|
|
// These flags allow a transaction to use TLS false start with
|
|
|
|
// weaker security profiles based on past history
|
|
|
|
#define NS_HTTP_ALLOW_RSA_FALSESTART (1<<9)
|
|
|
|
|
2014-10-21 18:35:41 +00:00
|
|
|
// This flag indicates the transaction should accept associated pushes
|
|
|
|
#define NS_HTTP_ONPUSH_LISTENER (1<<10)
|
|
|
|
|
2003-03-26 05:05:49 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// some default values
|
|
|
|
//-----------------------------------------------------------------------------
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2003-03-01 02:18:05 +00:00
|
|
|
#define NS_HTTP_DEFAULT_PORT 80
|
|
|
|
#define NS_HTTPS_DEFAULT_PORT 443
|
|
|
|
|
2003-05-13 04:38:25 +00:00
|
|
|
#define NS_HTTP_HEADER_SEPS ", \t"
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// http atoms...
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
struct nsHttpAtom
|
|
|
|
{
|
2006-02-17 22:52:40 +00:00
|
|
|
operator const char *() const { return _val; }
|
|
|
|
const char *get() const { return _val; }
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2001-09-26 23:30:28 +00:00
|
|
|
void operator=(const char *v) { _val = v; }
|
|
|
|
void operator=(const nsHttpAtom &a) { _val = a._val; }
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
// private
|
|
|
|
const char *_val;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nsHttp
|
|
|
|
{
|
2005-04-01 18:35:14 +00:00
|
|
|
static nsresult CreateAtomTable();
|
2001-05-11 21:04:09 +00:00
|
|
|
static void DestroyAtomTable();
|
|
|
|
|
2012-03-22 23:39:31 +00: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
|
2014-01-07 22:05:56 +00:00
|
|
|
static Mutex *GetLock();
|
2012-03-22 23:39:31 +00:00
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
// will dynamically add atoms to the table if they don't already exist
|
|
|
|
static nsHttpAtom ResolveAtom(const char *);
|
2005-04-01 18:35:14 +00:00
|
|
|
static nsHttpAtom ResolveAtom(const nsACString &s)
|
|
|
|
{
|
|
|
|
return ResolveAtom(PromiseFlatCString(s).get());
|
|
|
|
}
|
2001-05-11 21:04:09 +00:00
|
|
|
|
2006-04-07 17:45:44 +00:00
|
|
|
// returns true if the specified token [start,end) is valid per RFC 2616
|
|
|
|
// section 2.2
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool IsValidToken(const char *start, const char *end);
|
2006-04-07 17:45:44 +00:00
|
|
|
|
2014-07-24 16:38:55 +00:00
|
|
|
static inline bool IsValidToken(const nsACString &s) {
|
|
|
|
return IsValidToken(s.BeginReading(), s.EndReading());
|
2006-04-07 17:45:44 +00:00
|
|
|
}
|
|
|
|
|
2014-07-24 16:38:55 +00: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.
|
|
|
|
static bool IsReasonableHeaderValue(const nsACString &s);
|
|
|
|
|
2006-02-17 22:52:40 +00: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.
|
|
|
|
static const char *FindToken(const char *input, const char *token,
|
|
|
|
const char *separators);
|
|
|
|
|
2006-04-07 17:44:32 +00:00
|
|
|
// This function parses a string containing a decimal-valued, non-negative
|
2012-09-28 19:55:23 +00:00
|
|
|
// 64-bit integer. If the value would exceed INT64_MAX, then false is
|
2011-10-17 14:59:28 +00:00
|
|
|
// returned. Otherwise, this function returns true and stores the
|
2006-04-07 17:44:32 +00: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.
|
|
|
|
//
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool ParseInt64(const char *input, const char **next,
|
2012-08-22 15:56:38 +00:00
|
|
|
int64_t *result);
|
2006-04-07 17:44:32 +00:00
|
|
|
|
|
|
|
// Variant on ParseInt64 that expects the input string to contain nothing
|
|
|
|
// more than the value being parsed.
|
2012-08-22 15:56:38 +00:00
|
|
|
static inline bool ParseInt64(const char *input, int64_t *result) {
|
2006-04-07 17:44:32 +00:00
|
|
|
const char *next;
|
|
|
|
return ParseInt64(input, &next, result) && *next == '\0';
|
|
|
|
}
|
|
|
|
|
2012-09-22 15:27:17 +00:00
|
|
|
// Return whether the HTTP status code represents a permanent redirect
|
2012-10-01 20:04:09 +00:00
|
|
|
static bool IsPermanentRedirect(uint32_t httpStatus);
|
2012-09-22 15:27:17 +00:00
|
|
|
|
2006-02-17 22:52:40 +00:00
|
|
|
// Declare all atoms
|
2012-08-28 01:21:20 +00:00
|
|
|
//
|
2006-02-17 22:52:40 +00: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.
|
|
|
|
//
|
2001-05-11 21:04:09 +00:00
|
|
|
#define HTTP_ATOM(_name, _value) static nsHttpAtom _name;
|
|
|
|
#include "nsHttpAtomList.h"
|
|
|
|
#undef HTTP_ATOM
|
|
|
|
};
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// utilities...
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
static inline uint32_t
|
2001-05-11 21:04:09 +00:00
|
|
|
PRTimeToSeconds(PRTime t_usec)
|
|
|
|
{
|
2012-08-22 15:56:38 +00:00
|
|
|
return uint32_t( t_usec / PR_USEC_PER_SEC );
|
2001-05-11 21:04:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define NowInSeconds() PRTimeToSeconds(PR_Now())
|
|
|
|
|
2012-08-30 02:49:31 +00: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 20:51:12 +00:00
|
|
|
|
2003-06-18 23:16:17 +00:00
|
|
|
#define HTTP_LWS " \t"
|
2006-02-17 22:52:40 +00:00
|
|
|
#define HTTP_HEADER_VALUE_SEPS HTTP_LWS ","
|
2003-06-18 23:16:17 +00:00
|
|
|
|
2014-04-15 21:06:59 +00:00
|
|
|
void EnsureBuffer(nsAutoArrayPtr<char> &buf, uint32_t newSize,
|
|
|
|
uint32_t preserve, uint32_t &objSize);
|
|
|
|
void EnsureBuffer(nsAutoArrayPtr<uint8_t> &buf, uint32_t newSize,
|
|
|
|
uint32_t preserve, uint32_t &objSize);
|
|
|
|
|
2014-08-21 14:50:17 +00: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,
|
|
|
|
const char *val, int32_t valLen)
|
|
|
|
{
|
|
|
|
if (nameLen > 0) {
|
|
|
|
mName.Rebind(name, name + nameLen);
|
|
|
|
}
|
|
|
|
if (valLen > 0) {
|
|
|
|
mValue.Rebind(val, val + valLen);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ParsedHeaderPair(ParsedHeaderPair const ©)
|
|
|
|
: mName(copy.mName)
|
|
|
|
, mValue(copy.mValue)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDependentCSubstring mName;
|
|
|
|
nsDependentCSubstring mValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ParsedHeaderValueList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
ParsedHeaderValueList(char *t, uint32_t len);
|
|
|
|
nsTArray<ParsedHeaderPair> mValues;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void ParsePair(char *t, uint32_t len);
|
|
|
|
void Tokenize(char *input, uint32_t inputLen, char **token,
|
|
|
|
uint32_t *tokenLen, bool *foundEquals, char **next);
|
|
|
|
};
|
|
|
|
|
|
|
|
class ParsedHeaderValueListList
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit ParsedHeaderValueListList(const nsCString &txt);
|
|
|
|
nsTArray<ParsedHeaderValueList> mValues;
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCString mFull;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-01-07 22:05:56 +00:00
|
|
|
} // namespace mozilla::net
|
|
|
|
} // namespace mozilla
|
|
|
|
|
2001-08-14 01:03:27 +00:00
|
|
|
#endif // nsHttp_h__
|