📄 htreq.h
字号:
/*. Request Preconditions (HTTP If-* Headers).Should this request use preconditions when doing a PUT or aPOST? These are the "if-*" header fields that can be usedto avoid version conflicts etc. The default is not to use any preconsitions(HT_NO_MATCH). The _THIS versions use etags and/or timestamps and the _ANY versions use the "*" header field valueof the if-match and if-non-match header fields.*/typedef enum _HTPreconditions { HT_NO_MATCH = 0, HT_MATCH_THIS, HT_MATCH_ANY, HT_DONT_MATCH_THIS, HT_DONT_MATCH_ANY} HTPreconditions;extern void HTRequest_setPreconditions (HTRequest * me, HTPreconditions mode);extern HTPreconditions HTRequest_preconditions (HTRequest * me);/*. Local MIME header Parsers.MIMEParsers get their own type which is optimized for static and regex parserstrings.*/typedef struct _HTMIMEParseSet HTMIMEParseSet;extern void HTRequest_setMIMEParseSet (HTRequest *request, HTMIMEParseSet * parseSet, BOOL local);extern HTMIMEParseSet * HTRequest_MIMEParseSet (HTRequest *request, BOOL * pLocal);/*. Which Default Protocol Header Fields To Use?.Libwww supports a large set of headers that can be sent along with a request(or a response for that matter). All headers can be either disabled or enabledusing bit flags that are defined in the following. See also thesection on how to extend the default set of supported headerfields.( General HTTP Header Mask)There are a few header fields which have general applicability for both requestand response mesages, but which do not apply to the communication partiesor theentity being transferred. This mask enables and disables these headers.If the bit is not turned on they are not sent.*/typedef enum _HTGnHd { HT_G_CC = 0x1, HT_G_CONNECTION = 0x2, HT_G_DATE = 0x4, HT_G_PRAGMA_NO_CACHE= 0x8, HT_G_FORWARDED = 0x10, HT_G_MESSAGE_ID = 0x20, HT_G_MIME = 0x40, HT_G_TRAILER = 0x80, HT_G_TRANSFER = 0x100, HT_G_EXTRA_HEADERS = 0x200} HTGnHd;#define DEFAULT_GENERAL_HEADERS \ HT_G_CONNECTION + HT_G_CC + HT_G_TRANSFER + HT_G_TRAILER + \ HT_G_EXTRA_HEADERSextern void HTRequest_setGnHd (HTRequest *request, HTGnHd gnhd);extern void HTRequest_addGnHd (HTRequest *request, HTGnHd gnhd);extern HTGnHd HTRequest_gnHd (HTRequest *request);/*( Request Headers)The request header fields allow the client to pass additional informationabout the request (and about the client itself) to the server. All headersare optional but the default value is all request headers if presentexcept From and Pragma.*/typedef enum _HTRqHd { HT_C_ACCEPT_TYPE = 0x1, HT_C_ACCEPT_CHAR = 0x2, HT_C_ACCEPT_ENC = 0x4, HT_C_ACCEPT_TE = 0x8, HT_C_ACCEPT_LAN = 0x10, HT_C_AUTH = 0x20, /* Includes proxy authentication */ HT_C_EXPECT = 0x40, HT_C_FROM = 0x80, HT_C_HOST = 0x100, HT_C_IMS = 0x200, HT_C_IF_MATCH = 0x400, HT_C_IF_MATCH_ANY = 0x800, HT_C_IF_NONE_MATCH = 0x1000, HT_C_IF_NONE_MATCH_ANY=0x2000, HT_C_IF_RANGE = 0x4000, HT_C_IF_UNMOD_SINCE = 0x8000, HT_C_MAX_FORWARDS = 0x10000, HT_C_RANGE = 0x20000, HT_C_REFERER = 0x40000, HT_C_USER_AGENT = 0x80000} HTRqHd;#define DEFAULT_REQUEST_HEADERS \ HT_C_ACCEPT_TYPE + HT_C_ACCEPT_CHAR + \ HT_C_ACCEPT_ENC + HT_C_ACCEPT_TE + HT_C_ACCEPT_LAN + HT_C_AUTH + \ HT_C_EXPECT + HT_C_HOST + HT_C_REFERER + HT_C_USER_AGENTextern void HTRequest_setRqHd (HTRequest *request, HTRqHd rqhd);extern void HTRequest_addRqHd (HTRequest *request, HTRqHd rqhd);extern HTRqHd HTRequest_rqHd (HTRequest *request);/*( Response Headers)The response header fields allow the server to pass additional informationabout the response (and about the server itself) to the client. All headersare optional.*/typedef enum _HTRsHd { HT_S_AGE = 0x1, HT_S_LOCATION = 0x2, HT_S_PROXY_AUTH = 0x4, HT_S_PUBLIC = 0x8, HT_S_RETRY_AFTER = 0x10, HT_S_SERVER = 0x20, HT_S_VARY = 0x40, HT_S_WARNING = 0x80, HT_S_WWW_AUTH = 0x100, HT_S_TRAILER = 0x200} HTRsHd;#define DEFAULT_RESPONSE_HEADERS HT_S_SERVERextern void HTRequest_setRsHd (HTRequest * request, HTRsHd rshd);extern void HTRequest_addRsHd (HTRequest * request, HTRsHd rshd);extern HTRsHd HTRequest_rsHd (HTRequest * request);/*( Entity Header Mask)The entity headers contain information about the object sent in the HTTPtransaction. See the Anchor module, for the storageof entity headers. This flag defines which headers are to be sent in a requesttogether with an entity body. All headers are optional but the default valueis ALL ENTITY HEADERS IF PRESENT*/typedef enum _HTEnHd { HT_E_ALLOW = 0x1, HT_E_CONTENT_BASE = 0x2, HT_E_CONTENT_ENCODING = 0x4, HT_E_CONTENT_LANGUAGE = 0x8, HT_E_CONTENT_LENGTH = 0x10, HT_E_CONTENT_LOCATION = 0x20, HT_E_CONTENT_MD5 = 0x40, HT_E_CONTENT_RANGE = 0x80, HT_E_CTE = 0x100, /* Content-Transfer-Encoding */ HT_E_CONTENT_TYPE = 0x200, HT_E_DERIVED_FROM = 0x400, HT_E_ETAG = 0x800, HT_E_EXPIRES = 0x1000, HT_E_LAST_MODIFIED = 0x2000, HT_E_LINK = 0x4000, HT_E_TITLE = 0x8000, HT_E_URI = 0x10000, HT_E_VERSION = 0x20000} HTEnHd;#define DEFAULT_ENTITY_HEADERS 0xFFFFFFFF /* all */extern void HTRequest_setEnHd (HTRequest *request, HTEnHd enhd);extern void HTRequest_addEnHd (HTRequest *request, HTEnHd enhd);extern HTEnHd HTRequest_enHd (HTRequest *request);/*. Extending The Default Set Of Header Fields.See also how to set up default header fields. Thereare three ways to extend the set of headers that are sent in a request: o A simple association list o A stream oriented approach where the stream (called a generator) has direct access to the outgoing stream. That is, it can add any header it likes. o HTTP extension mechanism which is a much better way for handling extensions.( 1) Simple Association List)Add the (name, value) and it will be converted into MIME header format asname: value. Do NOT add CRLF line termination - this is done bythe HTTP header generator stream*/extern BOOL HTRequest_addExtraHeader (HTRequest * request, char * token, char * value);extern HTAssocList * HTRequest_extraHeader (HTRequest * request);extern BOOL HTRequest_deleteExtraHeaderAll (HTRequest * request);/*( 2) Stream Oriented Header Generators)Extra header information can be send along with a request usingheader generators. The text is sent as is soit must be preformatted with CRLF line terminators. You can alsoregister MIME header parsers using the HTHeadermodule.*/extern void HTRequest_setGenerator (HTRequest *request, HTList *gens, BOOL override);extern HTList * HTRequest_generator (HTRequest *request, BOOL *override);/*( 3) HTTP Extension Framework)These association lists contain the information that we are to send as HTTPExtension Framework. This is not done yet but you can find some hints inthe PEP module*//* TBD *//*. User And Application Preferences Using Accept Headers.The Accept family of headers is an important part of HTTP handling the formatnegotiation. The Library supports both a global set of accept headers thatare used in all HTTP requests and a local set of accept headersthat are used in specific requests only. The global ones are defined in theFormat Manager.Each request can have its local set of accept headers that either are addedto the global set or replaces the global set of accept headers. Non of theheaders have to be set. If the global set is sufficient for allrequests then this us perfectly fine. If the parameter "override" is setthen only local accept headers are used, else both local and globalheaders are used.( Content Types)The local list of specific conversions which the format managercan do in order to fulfill the request. It typically points to a list setup on initialisation time for example by HTInit().There is also a global list ofconversions which contains a generic set of possible conversions.*/extern void HTRequest_setConversion (HTRequest *request, HTList *type, BOOL override);extern HTList * HTRequest_conversion (HTRequest *request);/*( Content Encodings)The list of encodings acceptable in the output stream.*/extern void HTRequest_setEncoding (HTRequest *request, HTList *enc, BOOL override);extern HTList * HTRequest_encoding (HTRequest *request);/*( Transfer Encodings)The list of transfer encodings acceptable in the output stream.*/extern void HTRequest_setTransfer (HTRequest *request, HTList *te, BOOL override);extern HTList * HTRequest_transfer (HTRequest *request);/*( Content Languages)The list of (human) language values acceptable in the response. The defaultis all languages.*/extern void HTRequest_setLanguage (HTRequest *request, HTList *lang, BOOL override);extern HTList * HTRequest_language (HTRequest *request);/*( Content Charsets)The list of charsets accepted by the application*/extern void HTRequest_setCharset (HTRequest *request, HTList *charset, BOOL override);extern HTList * HTRequest_charset (HTRequest *request);/*. HTTP Cache Validation and Cache Control.The Library has two concepts of caching: in memory and on file. When loadinga document, this flag can be set in order to define who can give a responseto the request. The memory buffer is considered to be equivalent to a historybuffer. That is, it doesn't not follow the same expiration mechanism thatis characteristic for a persistent file cache.You can also set the cache to run in disconnected mode - see theCache manager for more details on how to do this.*/typedef enum _HTReload { HT_CACHE_OK = 0x0, /* Use any version available */ HT_CACHE_FLUSH_MEM = 0x1, /* Reload from file cache or network */ HT_CACHE_VALIDATE = 0x2, /* Validate cache entry */ HT_CACHE_END_VALIDATE = 0x4, /* End to end validation */ HT_CACHE_RANGE_VALIDATE = 0x8, HT_CACHE_FLUSH = 0x10, /* Force full reload */ HT_CACHE_ERROR = 0x20 /* An error occurred in the cache */} HTReload;extern void HTRequest_setReloadMode (HTRequest *request, HTReload mode);extern HTReload HTRequest_reloadMode (HTRequest *request);/*. Default PUT name.When publishing to a server which doesn't accept a URL ending in "/", e.g,the default Overview, index page, you can useHTRequest_setAltPutName to setup the intended URL. If thisvariable is defined, it'll be used during the cache lookup and updateoperationsm, so that cache-wise, it will look as if we had publishedonly to "/".*/extern char * HTRequest_defaultPutName (HTRequest * me);extern BOOL HTRequest_setDefaultPutName (HTRequest * me, char * name);extern BOOL HTRequest_deleteDefaultPutName (HTRequest * me);/*( HTTP Cache Control Directives)The cache control directives are all part of the cache control header andcontrol the behavior of any intermediate cache between the user agent andthe origin server. This association list is a list of the connection controldirectives that are to be sent as part of the Cache-Controlheader.*/extern BOOL HTRequest_addCacheControl (HTRequest * request, char * token, char *value);extern BOOL HTRequest_deleteCacheControlAll (HTRequest * request);extern HTAssocList * HTRequest_cacheControl (HTRequest * request);/*. Date and Time Stamp when Request was Issued.The start time when the request was issued may be of value to the cachevalidation mechanism as described by the HTTP/1.1 specification. The valueis automatically set when creating the request headers and sending off therequest. The time is a local time.*/extern time_t HTRequest_date (HTRequest * request);extern BOOL HTRequest_setDate (HTRequest * request, time_t date);/*. HTTP Expect Directives.The Expect request-header field is used to indicate that particular serverbehaviors are required by the client. A server that does not understand oris unable to comply with any of the expectation values in the Expect fieldof a request MUST respond with appropriate error status.*/extern BOOL HTRequest_addExpect (HTRequest * me, char * token, char * value);extern BOOL HTRequest_deleteExpect (HTRequest * me);extern HTAssocList * HTRequest_expect (HTRequest * me);/*. Partial Requests and Range Retrievals.Libwww can issue range requests in case we have already obtained a part ofthe entity body. Since all HTTP entities are represented in HTTP messagesas sequences of bytes, the concept of a byte range is meaningful for anyHTTP entity. (However, not all clients and servers need to support byte-rangeoperations.) Byte range specifications in HTTP apply to the sequence of bytesin the entity-body (not necessarily the same as the message-body). A byterange operation may specify a single range of bytes, or a set of ranges withina single entity.*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -