michael@0: /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim:set ts=4 sw=4 sts=4 et cin: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef nsHttp_h__ michael@0: #define nsHttp_h__ michael@0: michael@0: #include michael@0: #include "prtime.h" michael@0: #include "nsString.h" michael@0: #include "nsError.h" michael@0: michael@0: // http version codes michael@0: #define NS_HTTP_VERSION_UNKNOWN 0 michael@0: #define NS_HTTP_VERSION_0_9 9 michael@0: #define NS_HTTP_VERSION_1_0 10 michael@0: #define NS_HTTP_VERSION_1_1 11 michael@0: #define NS_HTTP_VERSION_2_0 20 michael@0: michael@0: namespace mozilla { michael@0: michael@0: class Mutex; michael@0: michael@0: namespace net { michael@0: enum { michael@0: SPDY_VERSION_2_REMOVED = 2, michael@0: SPDY_VERSION_3 = 3, michael@0: SPDY_VERSION_31 = 4, michael@0: michael@0: // leave room for official versions. telem goes to 48 michael@0: // 24 was a internal spdy/3.1 michael@0: // 25 was spdy/4a2 michael@0: // 26 was http/2-draft08 and http/2-draft07 (they were the same) michael@0: // 27 was also http/2-draft09 michael@0: HTTP2_VERSION_DRAFT10 = 27 michael@0: }; michael@0: michael@0: typedef uint8_t nsHttpVersion; michael@0: michael@0: #define NS_HTTP2_DRAFT_VERSION HTTP2_VERSION_DRAFT10 michael@0: #define NS_HTTP2_DRAFT_TOKEN "h2-10" michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: // http connection capabilities michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: #define NS_HTTP_ALLOW_KEEPALIVE (1<<0) michael@0: #define NS_HTTP_ALLOW_PIPELINING (1<<1) michael@0: michael@0: // a transaction with this caps flag will continue to own the connection, michael@0: // preventing it from being reclaimed, even after the transaction completes. michael@0: #define NS_HTTP_STICKY_CONNECTION (1<<2) michael@0: michael@0: // a transaction with this caps flag will, upon opening a new connection, michael@0: // bypass the local DNS cache michael@0: #define NS_HTTP_REFRESH_DNS (1<<3) michael@0: michael@0: // a transaction with this caps flag will not pass SSL client-certificates michael@0: // to the server (see bug #466080), but is may also be used for other things michael@0: #define NS_HTTP_LOAD_ANONYMOUS (1<<4) michael@0: michael@0: // a transaction with this caps flag keeps timing information michael@0: #define NS_HTTP_TIMING_ENABLED (1<<5) michael@0: michael@0: // a transaction with this flag blocks the initiation of other transactons michael@0: // in the same load group until it is complete michael@0: #define NS_HTTP_LOAD_AS_BLOCKING (1<<6) michael@0: michael@0: // Disallow the use of the SPDY protocol. This is meant for the contexts michael@0: // such as HTTP upgrade which are nonsensical for SPDY, it is not the michael@0: // SPDY configuration variable. michael@0: #define NS_HTTP_DISALLOW_SPDY (1<<7) michael@0: michael@0: // a transaction with this flag loads without respect to whether the load michael@0: // group is currently blocking on some resources michael@0: #define NS_HTTP_LOAD_UNBLOCKED (1<<8) michael@0: michael@0: // These flags allow a transaction to use TLS false start with michael@0: // weaker security profiles based on past history michael@0: #define NS_HTTP_ALLOW_RSA_FALSESTART (1<<9) michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: // some default values michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: #define NS_HTTP_DEFAULT_PORT 80 michael@0: #define NS_HTTPS_DEFAULT_PORT 443 michael@0: michael@0: #define NS_HTTP_HEADER_SEPS ", \t" michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: // http atoms... michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: struct nsHttpAtom michael@0: { michael@0: operator const char *() const { return _val; } michael@0: const char *get() const { return _val; } michael@0: michael@0: void operator=(const char *v) { _val = v; } michael@0: void operator=(const nsHttpAtom &a) { _val = a._val; } michael@0: michael@0: // private michael@0: const char *_val; michael@0: }; michael@0: michael@0: struct nsHttp michael@0: { michael@0: static nsresult CreateAtomTable(); michael@0: static void DestroyAtomTable(); michael@0: michael@0: // The mutex is valid any time the Atom Table is valid michael@0: // This mutex is used in the unusual case that the network thread and michael@0: // main thread might access the same data michael@0: static Mutex *GetLock(); michael@0: michael@0: // will dynamically add atoms to the table if they don't already exist michael@0: static nsHttpAtom ResolveAtom(const char *); michael@0: static nsHttpAtom ResolveAtom(const nsACString &s) michael@0: { michael@0: return ResolveAtom(PromiseFlatCString(s).get()); michael@0: } michael@0: michael@0: // returns true if the specified token [start,end) is valid per RFC 2616 michael@0: // section 2.2 michael@0: static bool IsValidToken(const char *start, const char *end); michael@0: michael@0: static inline bool IsValidToken(const nsCString &s) { michael@0: const char *start = s.get(); michael@0: return IsValidToken(start, start + s.Length()); michael@0: } michael@0: michael@0: // find the first instance (case-insensitive comparison) of the given michael@0: // |token| in the |input| string. the |token| is bounded by elements of michael@0: // |separators| and may appear at the beginning or end of the |input| michael@0: // string. null is returned if the |token| is not found. |input| may be michael@0: // null, in which case null is returned. michael@0: static const char *FindToken(const char *input, const char *token, michael@0: const char *separators); michael@0: michael@0: // This function parses a string containing a decimal-valued, non-negative michael@0: // 64-bit integer. If the value would exceed INT64_MAX, then false is michael@0: // returned. Otherwise, this function returns true and stores the michael@0: // parsed value in |result|. The next unparsed character in |input| is michael@0: // optionally returned via |next| if |next| is non-null. michael@0: // michael@0: // TODO(darin): Replace this with something generic. michael@0: // michael@0: static bool ParseInt64(const char *input, const char **next, michael@0: int64_t *result); michael@0: michael@0: // Variant on ParseInt64 that expects the input string to contain nothing michael@0: // more than the value being parsed. michael@0: static inline bool ParseInt64(const char *input, int64_t *result) { michael@0: const char *next; michael@0: return ParseInt64(input, &next, result) && *next == '\0'; michael@0: } michael@0: michael@0: // Return whether the HTTP status code represents a permanent redirect michael@0: static bool IsPermanentRedirect(uint32_t httpStatus); michael@0: michael@0: // Declare all atoms michael@0: // michael@0: // The atom names and values are stored in nsHttpAtomList.h and are brought michael@0: // to you by the magic of C preprocessing. Add new atoms to nsHttpAtomList michael@0: // and all support logic will be auto-generated. michael@0: // michael@0: #define HTTP_ATOM(_name, _value) static nsHttpAtom _name; michael@0: #include "nsHttpAtomList.h" michael@0: #undef HTTP_ATOM michael@0: }; michael@0: michael@0: //----------------------------------------------------------------------------- michael@0: // utilities... michael@0: //----------------------------------------------------------------------------- michael@0: michael@0: static inline uint32_t michael@0: PRTimeToSeconds(PRTime t_usec) michael@0: { michael@0: return uint32_t( t_usec / PR_USEC_PER_SEC ); michael@0: } michael@0: michael@0: #define NowInSeconds() PRTimeToSeconds(PR_Now()) michael@0: michael@0: // Round q-value to 2 decimal places; return 2 most significant digits as uint. michael@0: #define QVAL_TO_UINT(q) ((unsigned int) ((q + 0.005) * 100.0)) michael@0: michael@0: #define HTTP_LWS " \t" michael@0: #define HTTP_HEADER_VALUE_SEPS HTTP_LWS "," michael@0: michael@0: } // namespace mozilla::net michael@0: } // namespace mozilla michael@0: michael@0: #endif // nsHttp_h__