root / trunk / src / dot / proxy / http.h

Revision 7735, 5.5 kB (checked in by BradNeuberg, 22 months ago)

Created infrastructure to be able to give a 'testDomain' and a 'testDomainAddress' to test disconnected web applications on your own local machine -- Polipo doesn't look up the etc/hosts file, which would be difficult to parse, so we use this as an alternative. Tested on Safari, Firefox, and IE on Windows and Mac/x86

Line 
1/*
2Copyright (c) 2003-2006 by Juliusz Chroboczek
3
4Permission is hereby granted, free of charge, to any person obtaining a copy
5of this software and associated documentation files (the "Software"), to deal
6in the Software without restriction, including without limitation the rights
7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8copies of the Software, and to permit persons to whom the Software is
9furnished to do so, subject to the following conditions:
10
11The above copyright notice and this permission notice shall be included in
12all copies or substantial portions of the Software.
13
14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20THE SOFTWARE.
21*/
22
23typedef struct _HTTPCondition {
24    time_t ims;
25    time_t inms;
26    char *im;
27    char *inm;
28    char *ifrange;
29} HTTPConditionRec, *HTTPConditionPtr;
30
31typedef struct _HTTPRequest {
32    int flags;
33    struct _HTTPConnection *connection;
34    ObjectPtr object;
35    int method;
36    int from;
37    int to;
38    int replaying;
39    CacheControlRec cache_control;
40    HTTPConditionPtr condition;
41    AtomPtr via;
42    AtomPtr referer;
43    struct _ConditionHandler *chandler;
44    ObjectPtr can_mutate;
45    int error_code;
46    struct _Atom *error_message;
47    struct _Atom *error_headers;
48    AtomPtr headers;
49    struct timeval time0, time1;
50    struct _HTTPRequest *request;
51    struct _HTTPRequest *next;
52} HTTPRequestRec, *HTTPRequestPtr;
53
54/* request->flags */
55#define REQUEST_PERSISTENT 1
56#define REQUEST_REQUESTED 2
57#define REQUEST_WAIT_CONTINUE 4
58#define REQUEST_FORCE_ERROR 8
59#define REQUEST_PIPELINED 16
60
61typedef struct _HTTPConnection {
62    int flags;
63    int fd;
64    char *buf;
65    int len;
66    int offset;
67    HTTPRequestPtr request;
68    HTTPRequestPtr request_last;
69    int serviced;
70    int version;
71    TimeEventHandlerPtr timeout;
72    int te;
73    char *reqbuf;
74    int reqlen;
75    int reqbegin;
76    int reqoffset;
77    int bodylen;
78    int reqte;
79    /* For server connections */
80    int chunk_remaining;
81    struct _HTTPServer *server;
82    int pipelined;
83    int connecting;
84} HTTPConnectionRec, *HTTPConnectionPtr;
85
86/* connection->flags */
87#define CONN_READER 1
88#define CONN_WRITER 2
89#define CONN_SIDE_READER 4
90#define CONN_BIGBUF 8
91#define CONN_BIGREQBUF 16
92
93/* request->method */
94#define METHOD_UNKNOWN -1
95#define METHOD_NONE -1
96#define METHOD_GET 0
97#define METHOD_HEAD 1
98#define METHOD_CONDITIONAL_GET 2
99#define METHOD_CONNECT 3
100#define METHOD_POST 4
101#define METHOD_PUT 5
102
103#define REQUEST_SIDE(request) ((request)->method >= METHOD_POST)
104
105/* server->version */
106#define HTTP_10 0
107#define HTTP_11 1
108#define HTTP_UNKNOWN -1
109
110/* connection->te */
111#define TE_IDENTITY 0
112#define TE_CHUNKED 1
113#define TE_UNKNOWN -1
114
115/* connection->connecting */
116#define CONNECTING_DNS 1
117#define CONNECTING_CONNECT 2
118#define CONNECTING_SOCKS 3
119
120/* the results of a conditional request.  200, 304 and 412. */
121#define CONDITION_MATCH 0
122#define CONDITION_NOT_MODIFIED 1
123#define CONDITION_FAILED 2
124
125extern int disableProxy;
126extern AtomPtr proxyName;
127extern int proxyPort;
128extern int clientTimeout, serverTimeout, offlineTimeout;
129extern int bigBufferSize;
130extern AtomPtr proxyAddress;
131extern int proxyOffline;
132extern int relaxTransparency;
133extern AtomPtr authRealm;
134extern AtomPtr authCredentials;
135extern AtomPtr parentAuthCredentials;
136extern AtomListPtr allowedClients;
137extern NetAddressPtr allowedNets;
138extern IntListPtr allowedPorts;
139extern IntListPtr tunnelAllowedPorts;
140extern int expectContinue;
141extern AtomPtr atom100Continue;
142extern int disableVia;
143extern int dontTrustVaryETag;
144extern AtomPtr testDomain;
145extern AtomPtr testDomainAddress;
146
147void preinitHttp(void);
148void initHttp(void);
149
150int httpTimeoutHandler(TimeEventHandlerPtr);
151int httpSetTimeout(HTTPConnectionPtr connection, int secs);
152int httpWriteObjectHeaders(char *buf, int offset, int len,
153                           ObjectPtr object, int from, int to);
154int httpPrintCacheControl(char*, int, int, int, CacheControlPtr);
155char *httpMessage(int) ATTRIBUTE((pure));
156int htmlString(char *buf, int n, int len, char *s, int slen);
157void htmlPrint(FILE *out, char *s, int slen);
158HTTPConnectionPtr httpMakeConnection(void);
159void httpDestroyConnection(HTTPConnectionPtr connection);
160void httpConnectionDestroyBuf(HTTPConnectionPtr connection);
161void httpConnectionDestroyReqbuf(HTTPConnectionPtr connection);
162HTTPRequestPtr httpMakeRequest(void);
163void httpDestroyRequest(HTTPRequestPtr request, int destroyEverything);
164void httpQueueRequest(HTTPConnectionPtr, HTTPRequestPtr);
165HTTPRequestPtr httpDequeueRequest(HTTPConnectionPtr connection);
166int httpConnectionBigify(HTTPConnectionPtr);
167int httpConnectionBigifyReqbuf(HTTPConnectionPtr);
168int httpConnectionUnbigify(HTTPConnectionPtr);
169int httpConnectionUnbigifyReqbuf(HTTPConnectionPtr);
170HTTPConditionPtr httpMakeCondition(void);
171void httpDestroyCondition(HTTPConditionPtr condition);
172int httpCondition(ObjectPtr, HTTPConditionPtr);
173int httpWriteErrorHeaders(char *buf, int size, int offset, int do_body,
174                          int code, AtomPtr message, int close, AtomPtr,
175                          char *url, int url_len, char *etag);
176AtomListPtr urlDecode(char*, int);
177void httpTweakCachability(ObjectPtr);
178int httpHeaderMatch(AtomPtr header, AtomPtr headers1, AtomPtr headers2);
Note: See TracBrowser for help on using the browser.