Are there any constants for the default HTTP headers?

后端 未结 8 818
时光说笑
时光说笑 2021-02-01 00:21

Has Microsoft created a class full of constants for the standard HTTP header names or will I have to write my own?

8条回答
  •  隐瞒了意图╮
    2021-02-01 01:21

    Request Headers

    /// 
    /// Contains the standard set of headers applicable to an HTTP request.
    /// 
    public static class HttpRequestHeaders
    {
        ///Content-Types that are acceptable
        public const string Accept = "Accept";
        ///Character sets that are acceptable
        public const string AcceptCharset = "Accept-Charset";
        ///Acceptable encodings. See HTTP compression.
        public const string AcceptEncoding = "Accept-Encoding";
        ///Acceptable languages for response
        public const string AcceptLanguage = "Accept-Language";
        ///Acceptable version in time
        public const string AcceptDatetime = "Accept-Datetime";
        ///Authentication credentials for HTTP authentication
        public const string Authorization = "Authorization";
        ///Used to specify directives that MUST be obeyed by all caching mechanisms along the request/response chain
        public const string CacheControl = "Cache-Control";
        ///What type of connection the user-agent would prefer
        public const string Connection = "Connection";
        ///an HTTP cookie previously sent by the server with Set-Cookie (below)
        public const string Cookie = "Cookie";
        ///The length of the request body in octets (8-bit bytes)
        public const string ContentLength = "Content-Length";
        ///A Base64-encoded binary MD5 sum of the content of the request body
        public const string ContentMD5 = "Content-MD5";
        ///The MIME type of the body of the request (used with POST and PUT requests)
        public const string ContentType = "Content-Type";
        ///The date and time that the message was sent
        public const string Date = "Date";
        ///Indicates that particular server behaviors are required by the client
        public const string Expect = "Expect";
        ///The email address of the user making the request
        public const string From = "From";
        ///The domain name of the server (for virtual hosting), mandatory since HTTP/1.1. Although domain name are specified as case-insensitive[5][6], it is not specified whether the contents of the Host field should be interpreted in a case-insensitive manner[7] and in practice some implementations of virtual hosting interpret the contents of the Host field in a case-sensitive manner.[citation needed]
        public const string Host = "Host";
        ///Only perform the action if the client supplied entity matches the same entity on the server. This is mainly for methods like PUT to only update a resource if it has not been modified since the user last updated it.
        public const string IfMatch = "If-Match";
        ///Allows a 304 Not Modified to be returned if content is unchanged
        public const string IfModifiedSince = "If-Modified-Since";
        ///Allows a 304 Not Modified to be returned if content is unchanged, see HTTP ETag
        public const string IfNoneMatch = "If-None-Match";
        ///If the entity is unchanged, send me the part(s) that I am missing; otherwise, send me the entire new entity
        public const string IfRange = "If-Range";
        ///Only send the response if the entity has not been modified since a specific time.
        public const string IfUnmodifiedSince = "If-Unmodified-Since";
        ///Limit the number of times the message can be forwarded through proxies or gateways.
        public const string MaxForwards = "Max-Forwards";
        ///Implementation-specific headers that may have various effects anywhere along the request-response chain.
        public const string Pragma = "Pragma";
        ///Authorization credentials for connecting to a proxy.
        public const string ProxyAuthorization = "Proxy-Authorization";
        ///Request only part of an entity. Bytes are numbered from 0.
        public const string Range = "Range";
        ///This is the address of the previous web page from which a link to the currently requested page was followed. (The word “referrer” is misspelled in the RFC as well as in most implementations.)
        public const string Referersic = "Referer[sic]";
        ///The transfer encodings the user agent is willing to accept: the same values as for the response header Transfer-Encoding can be used, plus the trailers value (related to the chunked transfer method) to notify the server it expects to receive additional headers (the trailers) after the last, zero-sized, chunk.
        public const string TE = "TE";
        ///Ask the server to upgrade to another protocol.
        public const string Upgrade = "Upgrade";
        ///The user agent string of the user agent
        public const string UserAgent = "User-Agent";
        ///Informs the server of proxies through which the request was sent.
        public const string Via = "Via";
        ///A general warning about possible problems with the entity body.
        public const string Warning = "Warning";
        ///Contains the original source address of the request.
        public const string XForwardedFor = "X-Forwarded-For";
    }
    

    Response Headers

    /// 
    /// Contains the standard set of headers applicable to an HTTP response.
    /// 
    public static class HttpResponseHeaders
    {
        ///What partial content range types this server supports
        public const string AcceptRanges = "Accept-Ranges";
        ///The age the object has been in a proxy cache in seconds
        public const string Age = "Age";
        ///Valid actions for a specified resource. To be used for a 405 Method not allowed
        public const string Allow = "Allow";
        ///Tells all caching mechanisms from server to client whether they may cache this object. It is measured in seconds
        public const string CacheControl = "Cache-Control";
        ///Options that are desired for the connection[17]
        public const string Connection = "Connection";
        ///The type of encoding used on the data. See HTTP compression.
        public const string ContentEncoding = "Content-Encoding";
        ///The language the content is in
        public const string ContentLanguage = "Content-Language";
        ///The length of the response body in octets (8-bit bytes)
        public const string ContentLength = "Content-Length";
        ///An alternate location for the returned data
        public const string ContentLocation = "Content-Location";
        ///A Base64-encoded binary MD5 sum of the content of the response
        public const string ContentMD5 = "Content-MD5";
        ///An opportunity to raise a File Download dialogue box for a known MIME type with binary format or suggest a filename for dynamic content. Quotes are necessary with special characters.
        public const string ContentDisposition = "Content-Disposition";
        ///Where in a full body message this partial message belongs
        public const string ContentRange = "Content-Range";
        ///The MIME type of this content
        public const string ContentType = "Content-Type";
        ///The date and time that the message was sent
        public const string Date = "Date";
        ///An identifier for a specific version of a resource, often a message digest
        public const string ETag = "ETag";
        ///Gives the date/time after which the response is considered stale
        public const string Expires = "Expires";
        ///The last modified date for the requested object, inRFC 2822 format
        public const string LastModified = "Last-Modified";
        ///Used to express a typed relationship with another resource, where the relation type is defined by RFC 5988
        public const string Link = "Link";
        ///Used in redirection, or when a new resource has been created.
        public const string Location = "Location";
        ///This header is supposed to set P3P policy, in the form of P3P:CP=your_compact_policy. However, P3P did not take off,[22] most browsers have never fully implemented it, a lot of websites set this header with fake policy text, that was enough to fool browsers the existence of P3P policy and grant permissions for third party cookies.
        public const string P3P = "P3P";
        ///Implementation-specific headers that may have various effects anywhere along the request-response chain.
        public const string Pragma = "Pragma";
        ///Request authentication to access the proxy.
        public const string ProxyAuthenticate = "Proxy-Authenticate";
        ///Used in redirection, or when a new resource has been created. This refresh redirects after 5 seconds. This is a proprietary, non-standard header extension introduced by Netscape and supported by most web browsers.
        public const string Refresh = "Refresh";
        ///If an entity is temporarily unavailable, this instructs the client to try again after a specified period of time (seconds).
        public const string RetryAfter = "Retry-After";
        ///A name for the server
        public const string Server = "Server";
        ///an HTTP cookie
        public const string SetCookie = "Set-Cookie";
        ///A HSTS Policy informing the HTTP client how long to cache the HTTPS only policy and whether this applies to subdomains.
        public const string StrictTransportSecurity = "Strict-Transport-Security";
        ///The Trailer general field value indicates that the given set of header fields is present in the trailer of a message encoded with chunked transfer-coding.
        public const string Trailer = "Trailer";
        ///The form of encoding used to safely transfer the entity to the user. Currently defined methods are:chunked, compress, deflate, gzip, identity.
        public const string TransferEncoding = "Transfer-Encoding";
        ///Tells downstream proxies how to match future request headers to decide whether the cached response can be used rather than requesting a fresh one from the origin server.
        public const string Vary = "Vary";
        ///Informs the client of proxies through which the response was sent.
        public const string Via = "Via";
        ///A general warning about possible problems with the entity body.
        public const string Warning = "Warning";
        ///Indicates the authentication scheme that should be used to access the requested entity.
        public const string WWWAuthenticate = "WWW-Authenticate";       
    }
    

提交回复
热议问题