⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 htreq.h

📁 www工具包. 这是W3C官方支持的www支撑库. 其中提供通用目的的客户端的WebAPI: complete HTTP/1.1 (with caching, pipelining, PUT, POS
💻 H
📖 第 1 页 / 共 3 页
字号:
/*    					W3C Sample Code Library libwww Request Class!  The Request Class!*//***	(c) COPYRIGHT MIT 1995.**	Please first read the full copyright statement in the file COPYRIGH.*//*Libwww is based on a request/response paradigm and the Request class defines"an operation to be performed on a URL". The request object is themain entry point for an application to issue a request to the Library - alloperations on a URL must use a Request object. The request objectis application independent in that both servers and clients use the sameRequest class. Examples of requests passed to the Library are a clientapplication issuing a GET request on a HTTP URL, or a server issuinga load on a local file URL. The only difference is that the client gets theinput from a user whereas the server gets the input via the network.A request object is created with a default set of parameters which are applicablefor many URL requests but the class defines a huge set of methods that anbe used to customize a request for a particular purpose. Example of thingsthat you can define is natural language, media types, what RFC 822 headersto use, whether the request should be refreshed from cache etc. Scroll downand see the set of parameters you can tune.A request object is registered in the library by issuing an operation ona URL - for example PUT, POST, or DELETE. You can findmany higher level "request issuing functions" in theAccess module - the methods defined by the Requestclass itself are very low level but can of course be used directly if needed.Whereas the lifetime of the URL (in form of an anchor) often is very long(for example as long as the application is running), the lifetime of a requestis limited to the time it takes to service the request. The core does notautomatically delete any request object created by the application - it isfor the application to do. In many cases a request object can be deletedwhen any of the termination callback functionsare called but the application may keep request objects around longer thanthatThe Library can accept an unlimited number of simultaneous requests passedby the application. One of the main functions of the Library core is to handleany number of ongoing requests in an intelligent manner by limiting the numberof active request to the fit the available resources as defined by theapplication. This is described in more detail in the HTNetmodule.This module is implemented by HTReqMan.c, and itis a part of the  W3C Sample CodeLibrary.*/#ifndef HTREQ_H#define HTREQ_Htypedef long HTRequestID;typedef struct _HTRequest HTRequest;#include "HTEvent.h"#include "HTList.h"#include "HTAssoc.h"#include "HTFormat.h"#include "HTStream.h"#include "HTError.h"#include "HTNet.h"#include "HTUser.h"#include "HTResponse.h"/*.  Creation and Deletion Methods.The request object is intended to live as long as the request is still active,but can be deleted as soon as it has terminated, for example in one of therequest termination callback functions as described in theNet Manager. Only the anchor object stays aroundafter the request itself is terminated.(  Create new Object)Creates a new request object with a default set of options -- in most casesit will need some information added which can be done using the methods inthis module, but it will work as is for a simple request.*/extern HTRequest * HTRequest_new (void);/*(  Clear a Request Object)Clears all protocol specific information so that the request object can beused for another request. It should be used with care as application specificinformation is not re-initialized. Returns YES if OK, else NO.*/extern BOOL HTRequest_clear (HTRequest * me);/*(  Create a duplicate)Creates a new HTRequest object as a duplicate of the src request. ReturnsYES if OK, else NO*/extern HTRequest * HTRequest_dup (HTRequest * src);/*  Create a duplicate for Internal useCreates a new HTRequest object as a duplicate of the src request. The differenceto the HTRequest_dup function is that we don't copy the error_stack and otherinformation that the application keeps in its copy of the request object.Otherwise it will be freed multiple times. Returns YES if OK, else NO*/extern HTRequest * HTRequest_dupInternal (HTRequest * src);extern BOOL HTRequest_setInternal (HTRequest * request, BOOL mode);extern BOOL HTRequest_internal (HTRequest * request);/*(  Delete Object)This function deletes the object and cleans up the memory.*/extern void HTRequest_delete (HTRequest * request);/*.  Issuing a Request.These are the "basic request methods" provided directly by the Requestclass. This is a very low level API as the caller must have set up the requestobject before passing it to libwww. There are two versions: one for issuingclient requests and one for issuing server requests. You will probably mostoften use the client version, but, in fact, libwww can also deal with incomingconnections. You can find many higher level issuing functions in theHTAccess module. If you like, you can of courseuse this directly!*/extern BOOL HTLoad (HTRequest * request, BOOL recursive);extern BOOL HTServe(HTRequest * request, BOOL recursive);/*.  Killing a Request.This function kills this particular request, see HTNetmodule for a function that kills them all. If you know that you arepipelining requests (typically the case for GUI browsers, robots etc.) thenit is often not enough to just kill a single request as the whole pipelinegets affected. Therefore, in that case you MUST call theHTHost_killPipe function instead,*/extern BOOL HTRequest_kill(HTRequest * request);/*Note that you can get to the HTHost object via the HTNetobject which you can get by callingHTRequest_net(...)..  Relations to Other Libwww Objects.The Request object is linked to a set of other libwww objects - here's howto get to these objects...(  Binding to an Anchor Object)Every request object has an anchor associatedwith it. The anchor normally lives until the application terminates but arequest object only lives as long as the request is being serviced. If theanchor that we have requested is a child anchor then we always loadthe parent anchor; after the load jump to the location. A child anchoris a an anchor which points to a subpart of the document (has a "#" in theURL).*/extern void HTRequest_setAnchor (HTRequest *request, HTAnchor *anchor);extern HTParentAnchor * HTRequest_anchor (HTRequest *request);extern HTChildAnchor * HTRequest_childAnchor (HTRequest * request);/*(  Binding to a User Profile)Each request is associated with a User profilewhich contains information about the local host name, email address of theuser, news server etc. A request object is created with a default "genericuser" but can be assigned a specific user at any time.*/extern BOOL HTRequest_setUserProfile (HTRequest * request, HTUserProfile * up);extern HTUserProfile * HTRequest_userProfile (HTRequest * request);/*(  Binding to a Net Object)If a request is actually going on the net then the NetManager is contacted to handle the request. The Net manager creates aHTNEt object and links it to the Request object. You can get to the HTNetobject using the following functions.*/extern HTNet * HTRequest_net (HTRequest * request);extern BOOL HTRequest_setNet (HTRequest * request, HTNet * net);/*Note that you can go from the HTNet object to theHTHost object by calling HTNet_host(...).(  Binding to a Response Object)If a request is actually going on the net and we are getting a response backthen we also create a HTResponse object andbind it to the request object. Once we know what to do with the response,we may transfer the information to the anchor object.*/extern HTResponse * HTRequest_response (HTRequest * request);extern BOOL HTRequest_setResponse (HTRequest * request, HTResponse * response);/*.  Set the Method for the Request.The Method is the operation to be executed on the requested object. The defaultset if the set of operations defined by the HTTP protocol, that is "GET","HEAD", "PUT", "POST", "LINK", "UNLINK", and "DELETE" but many of these canbe used in other protocols as well. The important thing is to think of therequested element as an object on which you want to perform an operation.Then it is for the specific protocol implementation to try and carry thisoperation out. However, not all operations can be implemented (or make sense)in all protocols.Methods are handled by the Method Module, andthe default value is "GET".*/extern void HTRequest_setMethod (HTRequest *request, HTMethod method);extern HTMethod HTRequest_method (HTRequest *request);/*.  Priority Management.The request can be assigned an initial priority which then gets inheritedby all HTNet objects and other requests objectscreated as a result of this one. You can also assign a separate priorityto an indicidual HTNet object by using the methods in theNet manager.*/extern HTPriority HTRequest_priority (HTRequest * request);extern BOOL HTRequest_setPriority (HTRequest * request, HTPriority priority);/*.  Pipelining Managament.Libwww supports HTTP/1.1 pipelining which greatly optimizes HTTP's behaviorover TCP. libwww also tries very hard to minimize the number of TCP packetssent over the network. This is done by buffering outgoing requests untileither a minimum amount of data has been collected or a timeout causes aflush to happen. The application can override the output buffering by explicitrequest a request object to be flushed.*/extern BOOL HTRequest_setFlush (HTRequest * me, BOOL mode);extern BOOL HTRequest_flush (HTRequest * me);/*(  Force the Pipeline to be Flushed Immediately)Forcing a fluch immediatly is slightly different as this can be done in"retrospect". That is, if suddenly the application decides on performinga flush after the request was initiated then it can use this function toflush at a later time.*/extern int HTRequest_forceFlush (HTRequest * request);/*.  Dealing with Request Error Messages.Errors are, like almost anything,  kept in lists. An error list can beassociated with a request using the following functions. In order to make life easier, there are also some easy mapping functions to theHTError object, so that you can add an error directlyto a request object.*/extern HTList * HTRequest_error (HTRequest * request);extern void HTRequest_setError	(HTRequest * request, HTList * list);extern void HTRequest_deleteAllErrors (HTRequest * request);/*These are the cover functions that go directly to theError Object*/extern BOOL HTRequest_addError (HTRequest * 	request,				HTSeverity	severity,				BOOL		ignore,				int		element,				void *		par,				unsigned int	length,				char *		where);extern BOOL HTRequest_addSystemError (HTRequest * 	request,				      HTSeverity 	severity,				      int		errornumber,				      BOOL		ignore,				      char *		syscall);/*.  Max number of Retrys for a Down Load.Automatic reload can happen in two situations:	 	   o 	     The server sends a redirection response	   o 	     The document has expired	 	 In order to avoid the Library going into an infinite loop, it is necessaryto keep track of the number of automatic reloads. Loops can occur if theserver has a reload to the same document or if the server sends back a Expiresheader which has already expired. The default maximum number of automaticreloads is 6.*/extern BOOL HTRequest_setMaxRetry (int newmax);extern int  HTRequest_maxRetry (void);extern int HTRequest_retrys (HTRequest * request);extern BOOL HTRequest_doRetry (HTRequest *request);extern BOOL HTRequest_addRetry (HTRequest * request);extern int HTRequest_AAretrys (HTRequest * request);extern BOOL HTRequest_addAARetry (HTRequest * request);/*.  Set Max Forwards for TRACE methods.The TRACE method is used to invoke a remote, application-layerloop-back of the request message. The final recipient of the request SHOULDreflect the message received back to the client as the entity-body of a 200(OK) response. The final recipient is either the origin server or the firstproxy or gateway to receive a Max-Forwards value of zero (0) in the request.A TRACE request MUST NOT include an entity.*/extern BOOL HTRequest_setMaxForwards (HTRequest * request, int maxforwards);extern int HTRequest_maxForwards (HTRequest * request);/*.  Preemptive or Non-preemptive Access.An access scheme is defined with a default for using either preemptive (blockingI/O) or non-preemptive (non-blocking I/O). This is basically a result of theimplementation of the protocol module itself. However, if non-blocking I/Ois the default then some times it is nice to be able to set the mode to blockinginstead. For example, when loading the first document (the home page),blocking mode can be used instead of non-blocking.*/extern void HTRequest_setPreemptive (HTRequest *request, BOOL mode);extern BOOL HTRequest_preemptive (HTRequest *request);/*.  Content Negotiation.When accessing the local file system, the Library is capable of performingcontent negotioation as described by the HTTP protocol. This is mainly forserver applications, but some client applications might also want to usecontent negotiation when accessing the local file system. This method enablesor disables content negotiation - the default value is ON.*/extern void HTRequest_setNegotiation (HTRequest *request, BOOL mode);extern BOOL HTRequest_negotiation (HTRequest *request);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -