netwerk/protocol/http/nsHttp.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/protocol/http/nsHttp.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,196 @@
     1.4 +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
     1.5 +/* vim:set ts=4 sw=4 sts=4 et cin: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef nsHttp_h__
    1.11 +#define nsHttp_h__
    1.12 +
    1.13 +#include <stdint.h>
    1.14 +#include "prtime.h"
    1.15 +#include "nsString.h"
    1.16 +#include "nsError.h"
    1.17 +
    1.18 +// http version codes
    1.19 +#define NS_HTTP_VERSION_UNKNOWN  0
    1.20 +#define NS_HTTP_VERSION_0_9      9
    1.21 +#define NS_HTTP_VERSION_1_0     10
    1.22 +#define NS_HTTP_VERSION_1_1     11
    1.23 +#define NS_HTTP_VERSION_2_0     20
    1.24 +
    1.25 +namespace mozilla {
    1.26 +
    1.27 +class Mutex;
    1.28 +
    1.29 +namespace net {
    1.30 +    enum {
    1.31 +        SPDY_VERSION_2_REMOVED = 2,
    1.32 +        SPDY_VERSION_3 = 3,
    1.33 +        SPDY_VERSION_31 = 4,
    1.34 +
    1.35 +        // leave room for official versions. telem goes to 48
    1.36 +        // 24 was a internal spdy/3.1
    1.37 +        // 25 was spdy/4a2
    1.38 +        // 26 was http/2-draft08 and http/2-draft07 (they were the same)
    1.39 +        // 27 was also http/2-draft09
    1.40 +        HTTP2_VERSION_DRAFT10 = 27
    1.41 +    };
    1.42 +
    1.43 +typedef uint8_t nsHttpVersion;
    1.44 +
    1.45 +#define NS_HTTP2_DRAFT_VERSION HTTP2_VERSION_DRAFT10
    1.46 +#define NS_HTTP2_DRAFT_TOKEN "h2-10"
    1.47 +
    1.48 +//-----------------------------------------------------------------------------
    1.49 +// http connection capabilities
    1.50 +//-----------------------------------------------------------------------------
    1.51 +
    1.52 +#define NS_HTTP_ALLOW_KEEPALIVE      (1<<0)
    1.53 +#define NS_HTTP_ALLOW_PIPELINING     (1<<1)
    1.54 +
    1.55 +// a transaction with this caps flag will continue to own the connection,
    1.56 +// preventing it from being reclaimed, even after the transaction completes.
    1.57 +#define NS_HTTP_STICKY_CONNECTION    (1<<2)
    1.58 +
    1.59 +// a transaction with this caps flag will, upon opening a new connection,
    1.60 +// bypass the local DNS cache
    1.61 +#define NS_HTTP_REFRESH_DNS          (1<<3)
    1.62 +
    1.63 +// a transaction with this caps flag will not pass SSL client-certificates
    1.64 +// to the server (see bug #466080), but is may also be used for other things
    1.65 +#define NS_HTTP_LOAD_ANONYMOUS       (1<<4)
    1.66 +
    1.67 +// a transaction with this caps flag keeps timing information
    1.68 +#define NS_HTTP_TIMING_ENABLED       (1<<5)
    1.69 +
    1.70 +// a transaction with this flag blocks the initiation of other transactons
    1.71 +// in the same load group until it is complete
    1.72 +#define NS_HTTP_LOAD_AS_BLOCKING     (1<<6)
    1.73 +
    1.74 +// Disallow the use of the SPDY protocol. This is meant for the contexts
    1.75 +// such as HTTP upgrade which are nonsensical for SPDY, it is not the
    1.76 +// SPDY configuration variable.
    1.77 +#define NS_HTTP_DISALLOW_SPDY        (1<<7)
    1.78 +
    1.79 +// a transaction with this flag loads without respect to whether the load
    1.80 +// group is currently blocking on some resources
    1.81 +#define NS_HTTP_LOAD_UNBLOCKED       (1<<8)
    1.82 +
    1.83 +// These flags allow a transaction to use TLS false start with
    1.84 +// weaker security profiles based on past history
    1.85 +#define NS_HTTP_ALLOW_RSA_FALSESTART (1<<9)
    1.86 +
    1.87 +//-----------------------------------------------------------------------------
    1.88 +// some default values
    1.89 +//-----------------------------------------------------------------------------
    1.90 +
    1.91 +#define NS_HTTP_DEFAULT_PORT  80
    1.92 +#define NS_HTTPS_DEFAULT_PORT 443
    1.93 +
    1.94 +#define NS_HTTP_HEADER_SEPS ", \t"
    1.95 +
    1.96 +//-----------------------------------------------------------------------------
    1.97 +// http atoms...
    1.98 +//-----------------------------------------------------------------------------
    1.99 +
   1.100 +struct nsHttpAtom
   1.101 +{
   1.102 +    operator const char *() const { return _val; }
   1.103 +    const char *get() const { return _val; }
   1.104 +
   1.105 +    void operator=(const char *v) { _val = v; }
   1.106 +    void operator=(const nsHttpAtom &a) { _val = a._val; }
   1.107 +
   1.108 +    // private
   1.109 +    const char *_val;
   1.110 +};
   1.111 +
   1.112 +struct nsHttp
   1.113 +{
   1.114 +    static nsresult CreateAtomTable();
   1.115 +    static void DestroyAtomTable();
   1.116 +
   1.117 +    // The mutex is valid any time the Atom Table is valid
   1.118 +    // This mutex is used in the unusual case that the network thread and
   1.119 +    // main thread might access the same data
   1.120 +    static Mutex *GetLock();
   1.121 +
   1.122 +    // will dynamically add atoms to the table if they don't already exist
   1.123 +    static nsHttpAtom ResolveAtom(const char *);
   1.124 +    static nsHttpAtom ResolveAtom(const nsACString &s)
   1.125 +    {
   1.126 +        return ResolveAtom(PromiseFlatCString(s).get());
   1.127 +    }
   1.128 +
   1.129 +    // returns true if the specified token [start,end) is valid per RFC 2616
   1.130 +    // section 2.2
   1.131 +    static bool IsValidToken(const char *start, const char *end);
   1.132 +
   1.133 +    static inline bool IsValidToken(const nsCString &s) {
   1.134 +        const char *start = s.get();
   1.135 +        return IsValidToken(start, start + s.Length());
   1.136 +    }
   1.137 +
   1.138 +    // find the first instance (case-insensitive comparison) of the given
   1.139 +    // |token| in the |input| string.  the |token| is bounded by elements of
   1.140 +    // |separators| and may appear at the beginning or end of the |input|
   1.141 +    // string.  null is returned if the |token| is not found.  |input| may be
   1.142 +    // null, in which case null is returned.
   1.143 +    static const char *FindToken(const char *input, const char *token,
   1.144 +                                 const char *separators);
   1.145 +
   1.146 +    // This function parses a string containing a decimal-valued, non-negative
   1.147 +    // 64-bit integer.  If the value would exceed INT64_MAX, then false is
   1.148 +    // returned.  Otherwise, this function returns true and stores the
   1.149 +    // parsed value in |result|.  The next unparsed character in |input| is
   1.150 +    // optionally returned via |next| if |next| is non-null.
   1.151 +    //
   1.152 +    // TODO(darin): Replace this with something generic.
   1.153 +    //
   1.154 +    static bool ParseInt64(const char *input, const char **next,
   1.155 +                             int64_t *result);
   1.156 +
   1.157 +    // Variant on ParseInt64 that expects the input string to contain nothing
   1.158 +    // more than the value being parsed.
   1.159 +    static inline bool ParseInt64(const char *input, int64_t *result) {
   1.160 +        const char *next;
   1.161 +        return ParseInt64(input, &next, result) && *next == '\0';
   1.162 +    }
   1.163 +
   1.164 +    // Return whether the HTTP status code represents a permanent redirect
   1.165 +    static bool IsPermanentRedirect(uint32_t httpStatus);
   1.166 +
   1.167 +    // Declare all atoms
   1.168 +    //
   1.169 +    // The atom names and values are stored in nsHttpAtomList.h and are brought
   1.170 +    // to you by the magic of C preprocessing.  Add new atoms to nsHttpAtomList
   1.171 +    // and all support logic will be auto-generated.
   1.172 +    //
   1.173 +#define HTTP_ATOM(_name, _value) static nsHttpAtom _name;
   1.174 +#include "nsHttpAtomList.h"
   1.175 +#undef HTTP_ATOM
   1.176 +};
   1.177 +
   1.178 +//-----------------------------------------------------------------------------
   1.179 +// utilities...
   1.180 +//-----------------------------------------------------------------------------
   1.181 +
   1.182 +static inline uint32_t
   1.183 +PRTimeToSeconds(PRTime t_usec)
   1.184 +{
   1.185 +    return uint32_t( t_usec / PR_USEC_PER_SEC );
   1.186 +}
   1.187 +
   1.188 +#define NowInSeconds() PRTimeToSeconds(PR_Now())
   1.189 +
   1.190 +// Round q-value to 2 decimal places; return 2 most significant digits as uint.
   1.191 +#define QVAL_TO_UINT(q) ((unsigned int) ((q + 0.005) * 100.0))
   1.192 +
   1.193 +#define HTTP_LWS " \t"
   1.194 +#define HTTP_HEADER_VALUE_SEPS HTTP_LWS ","
   1.195 +
   1.196 +} // namespace mozilla::net
   1.197 +} // namespace mozilla
   1.198 +
   1.199 +#endif // nsHttp_h__

mercurial