Annotation of libwww/Library/src/HTTP.c, revision 1.148
1.74 frystyk 1: /* HTTP.c
2: ** MULTITHREADED IMPLEMENTATION OF HTTP CLIENT
1.2 timbl 3: **
1.84 frystyk 4: ** (c) COPYRIGHT MIT 1995.
1.74 frystyk 5: ** Please first read the full copyright statement in the file COPYRIGH.
1.148 ! frystyk 6: ** @(#) $Id: HTTP.c,v 1.147 1997年01月31日 22:55:24 frystyk Exp $
1.74 frystyk 7: **
8: ** This module implments the HTTP protocol as a state machine
1.55 frystyk 9: **
10: ** History:
1.59 frystyk 11: ** < May 24 94 ?? Unknown - but obviously written
1.56 frystyk 12: ** May 24 94 HF Made reentrent and cleaned up a bit. Implemented
13: ** Forward, redirection, error handling and referer field
1.67 duns 14: ** 8 Jul 94 FM Insulate free() from _free structure element.
1.71 frystyk 15: ** Jul 94 HFN Written on top of HTTP.c, Henrik Frystyk
1.55 frystyk 16: **
1.1 timbl 17: */
18:
1.78 frystyk 19: /* Library include files */
1.119 frystyk 20: #include "sysdep.h"
1.123 frystyk 21: #include "WWWUtil.h"
22: #include "WWWCore.h"
23: #include "WWWMIME.h"
24: #include "WWWStream.h"
1.125 frystyk 25: #include "WWWTrans.h"
1.94 frystyk 26: #include "HTReqMan.h"
1.95 frystyk 27: #include "HTNetMan.h"
1.109 frystyk 28: #include "HTTPUtil.h"
1.80 frystyk 29: #include "HTTPReq.h"
1.55 frystyk 30: #include "HTTP.h" /* Implements */
31:
32: /* Macros and other defines */
1.94 frystyk 33: #ifndef HTTP_PORT
34: #define HTTP_PORT 80 /* Allocated to http by Jon Postel/ISI 24-Jan-92 */
35: #endif
36:
1.71 frystyk 37: #define PUTC(c) (*me->target->isa->put_character)(me->target, c)
38: #define PUTS(s) (*me->target->isa->put_string)(me->target, s)
39: #define PUTBLOCK(b, l) (*me->target->isa->put_block)(me->target, b, l)
40: #define FREE_TARGET (*me->target->isa->_free)(me->target)
1.74 frystyk 41: #define ABORT_TARGET (*me->target->isa->abort)(me->target, e)
1.2 timbl 42:
1.140 frystyk 43: #define HTTP_DUMP
44: #ifdef HTTP_DUMP
1.147 frystyk 45: #define HTTP_OUTPUT "w3chttp.out"
1.140 frystyk 46: #endif
1.139 frystyk 47:
1.59 frystyk 48: /* Type definitions and global variables etc. local to this module */
1.94 frystyk 49:
50: /* Final states have negative value */
1.59 frystyk 51: typedef enum _HTTPState {
1.141 frystyk 52: HTTP_RECOVER_PIPE = -3,
1.134 frystyk 53: HTTP_ERROR = -2,
54: HTTP_OK = -1,
1.71 frystyk 55: HTTP_BEGIN = 0,
1.144 frystyk 56: HTTP_NEED_STREAM,
1.141 frystyk 57: HTTP_CONNECTED
1.59 frystyk 58: } HTTPState;
1.55 frystyk 59:
1.94 frystyk 60: /* This is the context structure for the this module */
1.55 frystyk 61: typedef struct _http_info {
1.81 frystyk 62: HTTPState state; /* Current State of the connection */
63: HTTPState next; /* Next state */
1.134 frystyk 64: int result; /* Result to report to the after filter */
1.139 frystyk 65: BOOL lock; /* Block for writing */
1.141 frystyk 66: HTNet * net;
1.55 frystyk 67: } http_info;
68:
1.88 frystyk 69: #define MAX_STATUS_LEN 100 /* Max nb of chars to check StatusLine */
1.55 frystyk 70:
1.71 frystyk 71: struct _HTStream {
1.119 frystyk 72: const HTStreamClass * isa;
1.71 frystyk 73: HTStream * target;
74: HTRequest * request;
75: http_info * http;
1.121 frystyk 76: HTEOLState state;
1.71 frystyk 77: BOOL transparent;
1.81 frystyk 78: char * version; /* Should we save this? */
1.71 frystyk 79: int status;
1.81 frystyk 80: char * reason;
1.71 frystyk 81: char buffer[MAX_STATUS_LEN+1];
1.80 frystyk 82: int buflen;
1.146 frystyk 83: int startLen;/* buflen when put_block was called */
1.71 frystyk 84: };
1.21 luotonen 85:
1.123 frystyk 86: struct _HTInputStream {
87: const HTInputStreamClass * isa;
88: };
89:
1.147 frystyk 90: #ifdef HT_NO_PIPELINING
91: PRIVATE HTTPConnectionMode ConnectionMode = HTTP_NO_PIPELINING;
92: #else
93: PRIVATE HTTPConnectionMode ConnectionMode = 0;
94: #endif
95:
1.71 frystyk 96: /* ------------------------------------------------------------------------- */
97: /* Help Functions */
98: /* ------------------------------------------------------------------------- */
1.21 luotonen 99:
1.94 frystyk 100: /* HTTPCleanup
101: ** -----------
1.55 frystyk 102: ** This function closes the connection and frees memory.
1.94 frystyk 103: ** Returns YES on OK, else NO
1.1 timbl 104: */
1.94 frystyk 105: PRIVATE int HTTPCleanup (HTRequest *req, int status)
1.1 timbl 106: {
1.126 frystyk 107: HTNet * net = HTRequest_net(req);
108: http_info * http = (http_info *) HTNet_context(net);
109: HTStream * input = HTRequest_inputStream(req);
1.80 frystyk 110:
1.144 frystyk 111: if (PROT_TRACE)
112: HTTrace("HTTP Clean.. Called with status %d, net %p\n", status, net);
113:
1.94 frystyk 114: /* Free stream with data TO network */
1.112 frystyk 115: if (HTRequest_isDestination(req))
116: HTRequest_removeDestination(req);
1.126 frystyk 117: else if (input) {
1.145 frystyk 118: if (status == HT_INTERRUPTED || status == HT_RECOVER_PIPE)
1.126 frystyk 119: (*input->isa->abort)(input, NULL);
1.94 frystyk 120: else
1.126 frystyk 121: (*input->isa->_free)(input);
122: HTRequest_setInputStream(req, NULL);
1.94 frystyk 123: }
1.88 frystyk 124:
1.144 frystyk 125: /*
126: ** Remove the request object and our own context structure for http.
127: */
128: if (status != HT_RECOVER_PIPE) {
129: HTNet_delete(net, status);
1.141 frystyk 130: HT_FREE(http);
131: }
1.94 frystyk 132: return YES;
1.55 frystyk 133: }
134:
1.71 frystyk 135: /*
1.130 frystyk 136: ** Informational 1xx codes are handled separately
1.136 frystyk 137: ** Returns YES if we should continue, NO if we should stop
1.55 frystyk 138: */
1.130 frystyk 139: PRIVATE BOOL HTTPInformation (HTStream * me)
1.55 frystyk 140: {
1.136 frystyk 141: http_info * http = me->http;
1.71 frystyk 142: switch (me->status) {
143:
1.136 frystyk 144: case 100:
145: HTRequest_addError(me->request, ERR_INFO, NO, HTERR_CONTINUE,
146: me->reason, (int) strlen(me->reason),
147: "HTTPInformation");
148: return YES;
149: break;
150:
1.130 frystyk 151: case 101:
1.136 frystyk 152: /*
153: ** We consider 101 Switching as a final state and exit this request
154: */
1.130 frystyk 155: HTRequest_addError(me->request, ERR_INFO, NO, HTERR_SWITCHING,
1.127 frystyk 156: me->reason, (int) strlen(me->reason),
1.130 frystyk 157: "HTTPInformation");
1.136 frystyk 158: http->next = HTTP_OK;
159: http->result = HT_UPGRADE;
1.127 frystyk 160: break;
161:
1.130 frystyk 162: default:
1.136 frystyk 163: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_BAD_REPLY,
164: (void *) me->buffer, me->buflen, "HTTPNextState");
165: http->next = HTTP_ERROR;
166: http->result = HT_ERROR;
1.127 frystyk 167: break;
1.130 frystyk 168: }
1.136 frystyk 169: return NO;
1.130 frystyk 170: }
171:
172: /*
173: ** This is a big switch handling all HTTP return codes. It puts in any
174: ** appropiate error message and decides whether we should expect data
175: ** or not.
176: */
177: PRIVATE void HTTPNextState (HTStream * me)
178: {
1.134 frystyk 179: http_info * http = me->http;
1.130 frystyk 180: switch (me->status) {
1.127 frystyk 181:
1.78 frystyk 182: case 0: /* 0.9 response */
1.127 frystyk 183: case 200: /* OK */
184: HTRequest_addError(me->request, ERR_INFO, NO, HTERR_OK,
185: me->reason, (int) strlen(me->reason),
186: "HTTPNextState");
1.134 frystyk 187: http->next = HTTP_OK;
188: http->result = HT_LOADED;
1.112 frystyk 189: break;
190:
1.127 frystyk 191: case 201: /* Created */
1.112 frystyk 192: HTRequest_addError(me->request, ERR_INFO, NO, HTERR_CREATED,
193: me->reason, (int) strlen(me->reason),
194: "HTTPNextState");
1.134 frystyk 195: http->next = HTTP_OK;
196: http->result = HT_CREATED;
1.112 frystyk 197: break;
198:
1.127 frystyk 199: case 202: /* Accepted */
1.112 frystyk 200: HTRequest_addError(me->request, ERR_INFO, NO, HTERR_ACCEPTED,
201: me->reason, (int) strlen(me->reason),
202: "HTTPNextState");
1.134 frystyk 203: http->next = HTTP_OK;
204: http->result = HT_ACCEPTED;
1.112 frystyk 205: break;
206:
1.127 frystyk 207: case 203: /* Non-authoritative information */
208: HTRequest_addError(me->request, ERR_INFO, NO, HTERR_NON_AUTHORITATIVE,
1.112 frystyk 209: me->reason, (int) strlen(me->reason),
210: "HTTPNextState");
1.134 frystyk 211: http->next = HTTP_OK;
212: http->result = HT_LOADED;
1.71 frystyk 213: break;
1.78 frystyk 214:
215: case 204: /* No Response */
1.112 frystyk 216: HTRequest_addError(me->request, ERR_INFO, NO, HTERR_NO_CONTENT,
217: me->reason, (int) strlen(me->reason),
218: "HTTPNextState");
1.134 frystyk 219: http->next = HTTP_OK;
220: http->result = HT_NO_DATA;
221: break;
222:
223: case 205: /* Reset Content */
224: HTRequest_addError(me->request, ERR_INFO, NO, HTERR_RESET,
225: me->reason, (int) strlen(me->reason),
226: "HTTPNextState");
227: http->next = HTTP_OK;
228: http->result = HT_RESET_CONTENT;
229: break;
230:
231: case 206: /* Partial Content */
232: HTRequest_addError(me->request, ERR_INFO, NO, HTERR_PARTIAL,
233: me->reason, (int) strlen(me->reason),
234: "HTTPNextState");
235: http->next = HTTP_OK;
236: http->result = HT_PARTIAL_CONTENT;
237: break;
238:
239: case 300: /* Multiple Choices */
240: HTRequest_addError(me->request, ERR_INFO, NO, HTERR_MULTIPLE,
241: me->reason, (int) strlen(me->reason),
242: "HTTPNextState");
243: http->next = HTTP_OK;
244: http->result = HT_LOADED;
1.71 frystyk 245: break;
1.78 frystyk 246:
1.71 frystyk 247: case 301: /* Moved */
1.112 frystyk 248: HTRequest_addError(me->request, ERR_INFO, NO, HTERR_MOVED,
249: me->reason, (int) strlen(me->reason),
250: "HTTPNextState");
1.134 frystyk 251: http->next = HTTP_ERROR;
252: http->result = HT_PERM_REDIRECT;
1.112 frystyk 253: break;
254:
1.71 frystyk 255: case 302: /* Found */
1.112 frystyk 256: HTRequest_addError(me->request, ERR_INFO, NO, HTERR_FOUND,
257: me->reason, (int) strlen(me->reason),
258: "HTTPNextState");
1.134 frystyk 259: http->next = HTTP_ERROR;
260: http->result = HT_TEMP_REDIRECT;
1.71 frystyk 261: break;
1.55 frystyk 262:
1.71 frystyk 263: case 303: /* Method */
1.107 frystyk 264: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_NOT_IMPLEMENTED,
265: me->reason, (int) strlen(me->reason),
266: "HTTPNextState");
1.134 frystyk 267: http->next = HTTP_ERROR;
268: http->result = HT_SEE_OTHER;
1.71 frystyk 269: break;
1.91 frystyk 270:
271: case 304: /* Not Modified */
1.131 frystyk 272: HTRequest_addError(me->request, ERR_INFO, NO, HTERR_NOT_MODIFIED,
1.112 frystyk 273: me->reason, (int) strlen(me->reason),
274: "HTTPNextState");
1.135 frystyk 275: http->next = HTTP_OK;
1.134 frystyk 276: http->result = HT_NOT_MODIFIED;
277: break;
278:
279: case 305: /* Use proxy */
280: HTRequest_addError(me->request, ERR_INFO, NO, HTERR_USE_PROXY,
281: me->reason, (int) strlen(me->reason),
282: "HTTPNextState");
283: http->next = HTTP_ERROR;
284: http->result = HT_USE_PROXY;
1.91 frystyk 285: break;
1.55 frystyk 286:
1.78 frystyk 287: case 400: /* Bad Request */
1.104 frystyk 288: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_BAD_REQUEST,
1.100 frystyk 289: me->reason, (int) strlen(me->reason), "HTTPNextState");
1.134 frystyk 290: http->next = HTTP_ERROR;
291: http->result = HT_ERROR;
1.71 frystyk 292: break;
1.70 howcome 293:
1.71 frystyk 294: case 401:
1.104 frystyk 295: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_UNAUTHORIZED,
1.100 frystyk 296: me->reason, (int) strlen(me->reason), "HTTPNextState");
1.134 frystyk 297: http->next = HTTP_ERROR;
298: http->result = HT_NO_ACCESS;
1.71 frystyk 299: break;
300:
301: case 402: /* Payment required */
1.104 frystyk 302: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_PAYMENT_REQUIRED,
1.100 frystyk 303: me->reason, (int) strlen(me->reason), "HTTPNextState");
1.134 frystyk 304: http->next = HTTP_ERROR;
305: http->result = HT_ERROR;
1.71 frystyk 306: break;
1.55 frystyk 307:
1.71 frystyk 308: case 403: /* Forbidden */
1.104 frystyk 309: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_FORBIDDEN,
1.100 frystyk 310: me->reason, (int) strlen(me->reason), "HTTPNextState");
1.134 frystyk 311: http->next = HTTP_ERROR;
312: http->result = HT_FORBIDDEN;
1.71 frystyk 313: break;
1.55 frystyk 314:
1.71 frystyk 315: case 404: /* Not Found */
1.104 frystyk 316: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_NOT_FOUND,
1.100 frystyk 317: me->reason, (int) strlen(me->reason), "HTTPNextState");
1.134 frystyk 318: http->next = HTTP_ERROR;
319: http->result = HT_ERROR;
1.71 frystyk 320: break;
321:
1.78 frystyk 322: case 405: /* Not Allowed */
1.104 frystyk 323: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_NOT_ALLOWED,
1.100 frystyk 324: me->reason, (int) strlen(me->reason), "HTTPNextState");
1.134 frystyk 325: http->next = HTTP_ERROR;
326: http->result = HT_ERROR;
1.78 frystyk 327: break;
328:
329: case 406: /* None Acceptable */
1.104 frystyk 330: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_NONE_ACCEPTABLE,
1.100 frystyk 331: me->reason, (int) strlen(me->reason), "HTTPNextState");
1.134 frystyk 332: http->next = HTTP_ERROR;
333: http->result = HT_NOT_ACCEPTABLE;
1.78 frystyk 334: break;
335:
336: case 407: /* Proxy Authentication Required */
1.127 frystyk 337: HTRequest_addError(me->request, ERR_FATAL, NO,HTERR_PROXY_UNAUTHORIZED,
1.100 frystyk 338: me->reason, (int) strlen(me->reason), "HTTPNextState");
1.134 frystyk 339: http->next = HTTP_ERROR;
340: http->result = HT_NO_PROXY_ACCESS;
1.78 frystyk 341: break;
342:
343: case 408: /* Request Timeout */
1.104 frystyk 344: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_TIMEOUT,
1.100 frystyk 345: me->reason, (int) strlen(me->reason), "HTTPNextState");
1.134 frystyk 346: http->next = HTTP_ERROR;
347: http->result = HT_ERROR;
348: break;
349:
350: case 409: /* Conflict */
351: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_CONFLICT,
352: me->reason, (int) strlen(me->reason), "HTTPNextState");
353: http->next = HTTP_ERROR;
354: http->result = HT_CONFLICT;
355: break;
356:
357: case 410: /* Gone */
358: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_GONE,
359: me->reason, (int) strlen(me->reason), "HTTPNextState");
360: http->next = HTTP_ERROR;
361: http->result = HT_ERROR;
362: break;
363:
364: case 411: /* Length Required */
365: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_LENGTH_REQUIRED,
366: me->reason, (int) strlen(me->reason), "HTTPNextState");
367: http->next = HTTP_ERROR;
368: http->result = HT_LENGTH_REQUIRED;
369: break;
370:
371: case 412: /* Precondition failed */
372: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_PRECON_FAILED,
373: me->reason, (int) strlen(me->reason), "HTTPNextState");
374: http->next = HTTP_ERROR;
375: http->result = HT_ERROR;
376: break;
377:
378: case 413: /* Request entity too large */
379: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_TOO_BIG,
380: me->reason, (int) strlen(me->reason), "HTTPNextState");
381: http->next = HTTP_ERROR;
382: http->result = HT_ERROR;
383: break;
384:
385: case 414: /* Request-URI too long */
386: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_URI_TOO_BIG,
387: me->reason, (int) strlen(me->reason), "HTTPNextState");
388: http->next = HTTP_ERROR;
389: http->result = HT_ERROR;
390: break;
391:
392: case 415: /* Unsupported */
393: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_UNSUPPORTED,
394: me->reason, (int) strlen(me->reason), "HTTPNextState");
395: http->next = HTTP_ERROR;
396: http->result = HT_ERROR;
1.78 frystyk 397: break;
398:
1.71 frystyk 399: case 500:
1.104 frystyk 400: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_INTERNAL,
1.100 frystyk 401: me->reason, (int) strlen(me->reason), "HTTPNextState");
1.134 frystyk 402: http->next = HTTP_ERROR;
403: http->result = HT_ERROR;
1.78 frystyk 404: break;
405:
1.71 frystyk 406: case 501:
1.104 frystyk 407: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_NOT_IMPLEMENTED,
1.100 frystyk 408: me->reason, (int) strlen(me->reason), "HTTPNextState");
1.134 frystyk 409: http->next = HTTP_ERROR;
410: http->result = HT_ERROR;
1.78 frystyk 411: break;
412:
413: case 502:
1.104 frystyk 414: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_BAD_GATE,
1.100 frystyk 415: me->reason, (int) strlen(me->reason), "HTTPNextState");
1.134 frystyk 416: http->next = HTTP_ERROR;
417: http->result = HT_ERROR;
1.78 frystyk 418: break;
419:
420: case 503:
1.104 frystyk 421: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_DOWN,
1.100 frystyk 422: me->reason, (int) strlen(me->reason), "HTTPNextState");
1.134 frystyk 423: http->next = HTTP_ERROR;
1.81 frystyk 424:
1.140 frystyk 425: /*
426: ** If Retry-After header is found then return HT_RETRY else HT_ERROR.
427: ** The caller may want to reissue the request at a later point in time.
428: */
429: {
430: HTResponse * response = HTRequest_response(me->request);
431: if (HTResponse_retryTime(response))
432: http->result = HT_RETRY;
433: else
434: http->result = HT_ERROR;
435: }
1.78 frystyk 436: break;
437:
438: case 504:
1.104 frystyk 439: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_GATE_TIMEOUT,
1.100 frystyk 440: me->reason, (int) strlen(me->reason), "HTTPNextState");
1.134 frystyk 441: http->next = HTTP_ERROR;
442: http->result = HT_ERROR;
443: break;
444:
445: case 505: /* Unsupported protocol version */
446: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_BAD_VERSION,
447: me->reason, (int) strlen(me->reason), "HTTPNextState");
448: http->next = HTTP_ERROR;
449: http->result = HT_BAD_VERSION;
1.71 frystyk 450: break;
1.78 frystyk 451:
1.71 frystyk 452: default: /* bad number */
1.104 frystyk 453: HTRequest_addError(me->request, ERR_FATAL, NO, HTERR_BAD_REPLY,
1.100 frystyk 454: (void *) me->buffer, me->buflen, "HTTPNextState");
1.134 frystyk 455: http->next = HTTP_ERROR;
456: http->result = HT_ERROR;
1.71 frystyk 457: break;
1.55 frystyk 458: }
459: }
460:
1.71 frystyk 461: /* ------------------------------------------------------------------------- */
462: /* HTTP Status Line Stream */
463: /* ------------------------------------------------------------------------- */
1.55 frystyk 464:
1.71 frystyk 465: /*
1.141 frystyk 466: ** Analyze the stream we have read. If it is a HTTP 1.0 or higher
1.71 frystyk 467: ** then create a MIME-stream, else create a Guess stream to find out
468: ** what the 0.9 server is sending. We need to copy the buffer as we don't
469: ** know if we can modify the contents or not.
1.78 frystyk 470: **
471: ** Stream handling is a function of the status code returned from the
472: ** server:
473: ** 200: Use `output_stream' in HTRequest structure
1.94 frystyk 474: ** else: Use `debug_stream' in HTRequest structure
1.80 frystyk 475: **
476: ** Return: YES if buffer should be written out. NO otherwise
1.56 frystyk 477: */
1.100 frystyk 478: PRIVATE int stream_pipe (HTStream * me)
1.56 frystyk 479: {
1.136 frystyk 480: HTRequest * request = me->request;
481: HTNet * net = HTRequest_net(request);
1.123 frystyk 482: HTHost * host = HTNet_host(net);
1.141 frystyk 483:
1.80 frystyk 484: if (me->target) {
485: int status = PUTBLOCK(me->buffer, me->buflen);
486: if (status == HT_OK)
487: me->transparent = YES;
488: return status;
1.136 frystyk 489: } else if (HTRequest_isSource(request)&&!HTRequest_outputStream(request)) {
1.88 frystyk 490: /*
491: ** We need to wait for the destinations to get ready
492: */
493: return HT_WOULD_BLOCK;
1.80 frystyk 494: }
1.88 frystyk 495:
1.132 frystyk 496: /*
497: ** Just check for HTTP and not HTTP/ as NCSA server chokes on 1.1 replies
498: ** Thanks to Markku Savela <msa@msa.tte.vtt.fi>
1.141 frystyk 499:
1.132 frystyk 500: */
501: #if 0
1.81 frystyk 502: if (strncasecomp(me->buffer, "http/", 5)) {
1.132 frystyk 503: #else
504: if (strncasecomp(me->buffer, "http", 4)) {
505: #endif
1.80 frystyk 506: int status;
1.136 frystyk 507: HTRequest_addError(request, ERR_INFO, NO, HTERR_HTTP09,
1.80 frystyk 508: (void *) me->buffer, me->buflen, "HTTPStatusStream");
1.136 frystyk 509: me->target = HTStreamStack(WWW_UNKNOWN,
510: HTRequest_outputFormat(request),
511: HTRequest_outputStream(request),
512: request, NO);
1.134 frystyk 513: me->http->next = HTTP_OK;
1.80 frystyk 514: if ((status = PUTBLOCK(me->buffer, me->buflen)) == HT_OK)
515: me->transparent = YES;
1.123 frystyk 516: HTHost_setVersion(host, HTTP_09);
1.80 frystyk 517: return status;
518: } else {
1.140 frystyk 519: HTResponse * response = HTRequest_response(request);
1.133 frystyk 520: char *ptr = me->buffer+4; /* Skip the HTTP part */
1.81 frystyk 521: me->version = HTNextField(&ptr);
1.146 frystyk 522: HTHost_setConsumed(net->host, me->buflen - me->startLen);
1.95 frystyk 523:
1.130 frystyk 524: /* Here we want to find out when to use persistent connection */
1.133 frystyk 525: if (!strncasecomp(me->version, "/1.0", 4)) {
1.128 frystyk 526: if (PROT_TRACE)HTTrace("HTTP Status. This is a HTTP/1.0 server\n");
527: HTHost_setVersion(host, HTTP_10);
1.133 frystyk 528: } else if (!strncasecomp(me->version, "/1.", 3)) { /* 1.x family */
1.128 frystyk 529: HTHost_setVersion(host, HTTP_11);
1.141 frystyk 530: #ifdef HT_MUX
531: HTNet_setPersistent(net, YES, HT_TP_INTERLEAVE);
532: #else
1.147 frystyk 533: if (ConnectionMode & HTTP_NO_PIPELINING) {
534: if (PROT_TRACE) HTTrace("HTTP........ Mode is HTTP/1.1 WITH NO PIPELINING\n");
535: HTNet_setPersistent(net, YES, HT_TP_SINGLE);
536: } else if (ConnectionMode & HTTP_FORCE_10) {
537: if (PROT_TRACE) HTTrace("HTTP........ Mode is FORCE HTTP/1.0\n");
538: HTHost_setVersion(host, HTTP_10);
539: HTNet_setPersistent(net, NO, HT_TP_SINGLE);
540: } else
541: HTNet_setPersistent(net, YES, HT_TP_PIPELINE);
1.145 frystyk 542: #endif /* HT_MUX */
1.133 frystyk 543: } else {
544: if (PROT_TRACE)HTTrace("HTTP Status. No 1.x version number - treat it as a HTTP/1.0 server\n");
545: HTHost_setVersion(host, HTTP_10);
1.128 frystyk 546: }
1.95 frystyk 547:
1.81 frystyk 548: me->status = atoi(HTNextField(&ptr));
1.133 frystyk 549: /* Kludge to fix the NCSA server version bug */
550: if (me->status == 0) me->status = atoi(me->version);
551:
1.81 frystyk 552: me->reason = ptr;
553: if ((ptr = strchr(me->reason, '\r')) != NULL) /* Strip \r and \n */
554: *ptr = '0円';
555: else if ((ptr = strchr(me->reason, '\n')) != NULL)
556: *ptr = '0円';
557:
1.130 frystyk 558: /*
559: ** If it is a 1xx code then find out what to do and return until we
560: ** get the next code. In the case of Upgrade we may not get back here
561: ** at all. If we are uploading an entity then continue doing that
562: */
563: if (me->status/100 == 1) {
1.136 frystyk 564: if (HTTPInformation(me) == YES) {
565: me->buflen = 0;
566: me->state = EOL_BEGIN;
567: return HTMethod_hasEntity(HTRequest_method(request)) ?
568: HT_CONTINUE : HT_OK;
1.103 frystyk 569: }
1.56 frystyk 570: }
1.133 frystyk 571:
572: /*
573: ** As we are getting fresh metainformation in the HTTP response,
574: ** we clear the old metainfomation in order not to mix it with the new
575: ** one. This is particularly important for the content-length and the
1.139 frystyk 576: ** like. The TRACE and OPTIONS method just adds to the current
577: ** metainformation so in that case we don't clear the anchor.
1.133 frystyk 578: */
1.136 frystyk 579: if (me->status==200 || me->status==203 || me->status==300) {
1.140 frystyk 580: /*
581: ** 200, 203 and 300 are all fully cacheable responses. No byte
582: ** ranges or anything else make life hard in this case.
583: */
1.148 ! frystyk 584: HTAnchor_clearHeader(HTRequest_anchor(request));
1.140 frystyk 585: HTResponse_setCachable(response, YES);
1.136 frystyk 586: me->target = HTStreamStack(WWW_MIME,
587: HTRequest_outputFormat(request),
588: HTRequest_outputStream(request),
589: request, NO);
1.140 frystyk 590: } else if (me->status==206) {
591: /*
592: ** We got a partial response and now we must check whether
593: ** we issued a cache If-Range request or it was a new
594: ** partial response which we don't have in cache. In the latter
595: ** case, we don't cache the object and in the former we append
596: ** the result to the already existing cache entry.
597: */
598: HTReload reload = HTRequest_reloadMode(request);
599: if (reload == HT_CACHE_RANGE_VALIDATE) {
600: HTResponse_setCachable(response, YES);
601: me->target = HTStreamStack(WWW_MIME_PART,
602: HTRequest_outputFormat(request),
603: HTRequest_outputStream(request),
604: request, NO);
605: } else {
606: me->target = HTStreamStack(WWW_MIME,
607: HTRequest_outputFormat(request),
608: HTRequest_outputStream(request),
609: request, NO);
610: }
1.139 frystyk 611: } else if (me->status==204 || me->status==304) {
1.140 frystyk 612: HTResponse_setCachable(response, YES);
1.136 frystyk 613: me->target = HTStreamStack(WWW_MIME_HEAD,
614: HTRequest_debugFormat(request),
615: HTRequest_debugStream(request),
616: request, NO);
617: } else if (HTRequest_debugStream(request)) {
618: me->target = HTStreamStack(WWW_MIME,
619: HTRequest_debugFormat(request),
620: HTRequest_debugStream(request),
621: request, NO);
622: } else {
1.140 frystyk 623: /*
624: ** We still need to parse the MIME part in order to find any
625: ** valuable meta information which is needed from the response.
626: */
1.136 frystyk 627: me->target = HTStreamStack(WWW_MIME,
628: HTRequest_debugFormat(request),
629: HTRequest_debugStream(request),
630: request, NO);
1.133 frystyk 631: }
1.56 frystyk 632: }
1.113 frystyk 633: if (!me->target) me->target = HTErrorStream();
1.81 frystyk 634: HTTPNextState(me); /* Get next state */
1.80 frystyk 635: me->transparent = YES;
636: return HT_OK;
1.71 frystyk 637: }
1.56 frystyk 638:
1.80 frystyk 639: /*
640: ** Searches for HTTP header line until buffer fills up or a CRLF or LF
641: ** is found
642: */
1.119 frystyk 643: PRIVATE int HTTPStatus_put_block (HTStream * me, const char * b, int l)
1.71 frystyk 644: {
1.146 frystyk 645: me->startLen = me->buflen;
1.80 frystyk 646: while (!me->transparent && l-- > 0) {
647: int status;
648: if (me->target) {
649: if ((status = stream_pipe(me)) != HT_OK)
650: return status;
651: } else {
652: *(me->buffer+me->buflen++) = *b;
653: if (me->state == EOL_FCR) {
654: if (*b == LF) { /* Line found */
655: if ((status = stream_pipe(me)) != HT_OK)
656: return status;
657: } else {
658: me->state = EOL_BEGIN;
659: }
660: } else if (*b == CR) {
661: me->state = EOL_FCR;
662: } else if (*b == LF) {
663: if ((status = stream_pipe(me)) != HT_OK)
664: return status;
1.71 frystyk 665: } else {
1.80 frystyk 666: if (me->buflen >= MAX_STATUS_LEN) {
667: if ((status = stream_pipe(me)) != HT_OK)
668: return status;
669: }
1.71 frystyk 670: }
1.80 frystyk 671: b++;
1.71 frystyk 672: }
1.56 frystyk 673: }
1.99 frystyk 674: if (l > 0) return PUTBLOCK(b, l);
675: return HT_OK;
1.56 frystyk 676: }
677:
1.119 frystyk 678: PRIVATE int HTTPStatus_put_string (HTStream * me, const char * s)
1.71 frystyk 679: {
1.80 frystyk 680: return HTTPStatus_put_block(me, s, (int) strlen(s));
1.71 frystyk 681: }
1.56 frystyk 682:
1.100 frystyk 683: PRIVATE int HTTPStatus_put_character (HTStream * me, char c)
1.71 frystyk 684: {
1.80 frystyk 685: return HTTPStatus_put_block(me, &c, 1);
686: }
687:
1.100 frystyk 688: PRIVATE int HTTPStatus_flush (HTStream * me)
1.80 frystyk 689: {
690: return (*me->target->isa->flush)(me->target);
1.71 frystyk 691: }
692:
1.100 frystyk 693: PRIVATE int HTTPStatus_free (HTStream * me)
1.71 frystyk 694: {
1.87 frystyk 695: int status = HT_OK;
696: if (me->target) {
697: if ((status = (*me->target->isa->_free)(me->target))==HT_WOULD_BLOCK)
698: return HT_WOULD_BLOCK;
699: }
1.115 frystyk 700: HT_FREE(me);
1.100 frystyk 701: return status;
1.71 frystyk 702: }
703:
1.104 frystyk 704: PRIVATE int HTTPStatus_abort (HTStream * me, HTList * e)
1.71 frystyk 705: {
706: if (me->target)
1.74 frystyk 707: ABORT_TARGET;
1.115 frystyk 708: HT_FREE(me);
1.74 frystyk 709: if (PROT_TRACE)
1.116 eric 710: HTTrace("HTTPStatus.. ABORTING...\n");
1.80 frystyk 711: return HT_ERROR;
1.71 frystyk 712: }
713:
714: /* HTTPStatus Stream
715: ** -----------------
716: */
1.119 frystyk 717: PRIVATE const HTStreamClass HTTPStatusClass =
1.71 frystyk 718: {
719: "HTTPStatus",
1.80 frystyk 720: HTTPStatus_flush,
1.71 frystyk 721: HTTPStatus_free,
722: HTTPStatus_abort,
723: HTTPStatus_put_character,
724: HTTPStatus_put_string,
725: HTTPStatus_put_block
726: };
727:
1.113 frystyk 728: PUBLIC HTStream * HTTPStatus_new (HTRequest * request,
729: void * param,
730: HTFormat input_format,
731: HTFormat output_format,
732: HTStream * output_stream)
1.71 frystyk 733: {
1.115 frystyk 734: HTStream * me;
735: if ((me = (HTStream *) HT_CALLOC(1, sizeof(HTStream))) == NULL)
736: HT_OUTOFMEM("HTTPStatus_new");
1.71 frystyk 737: me->isa = &HTTPStatusClass;
1.113 frystyk 738: if (request) {
1.126 frystyk 739: HTNet * net = HTRequest_net(request);
1.125 frystyk 740: /* Get existing copy */
741: http_info * http = (http_info *) HTNet_context(net);
1.113 frystyk 742: me->request = request;
743: me->http = http;
744: http->next = HTTP_ERROR;
745: me->state = EOL_BEGIN;
746: return me;
747: } else
748: return HTErrorStream();
1.71 frystyk 749: }
750:
751: /* ------------------------------------------------------------------------- */
752:
753: /* Load Document from HTTP Server HTLoadHTTP
1.55 frystyk 754: ** ==============================
755: **
756: ** Given a hypertext address, this routine loads a document.
757: **
758: ** On entry,
759: ** request This is the request structure
1.94 frystyk 760: ** returns HT_ERROR Error has occured in call back
761: ** HT_OK Call back was OK
1.55 frystyk 762: */
1.141 frystyk 763: PRIVATE int HTTPEvent (SOCKET soc, void * pVoid, HTEventType type);
764:
765: PUBLIC int HTLoadHTTP (SOCKET soc, HTRequest * request)
1.55 frystyk 766: {
767: http_info *http; /* Specific protocol information */
1.112 frystyk 768: HTParentAnchor *anchor = HTRequest_anchor(request);
1.141 frystyk 769: HTNet * net = HTRequest_net(request);
1.112 frystyk 770:
1.94 frystyk 771: /*
772: ** Initiate a new http structure and bind to request structure
773: ** This is actually state HTTP_BEGIN, but it can't be in the state
774: ** machine as we need the structure first.
775: */
1.141 frystyk 776: if (PROT_TRACE) HTTrace("HTTP........ Looking for `%s\'\n",
777: HTAnchor_physical(anchor));
778: if ((http = (http_info *) HT_CALLOC(1, sizeof(http_info))) == NULL)
779: HT_OUTOFMEM("HTLoadHTTP");
780: http->net = net;
781: HTNet_setContext(net, http);
782: HTNet_setEventCallback(net, HTTPEvent);
783: HTNet_setEventParam(net, http); /* callbacks get http* */
784:
785: return HTTPEvent(soc, http, HTEvent_BEGIN); /* get it started - ops is ignored */
786: }
787:
788: PRIVATE int HTTPEvent (SOCKET soc, void * pVoid, HTEventType type)
789: {
790: http_info * http = (http_info *)pVoid;
791: int status = HT_ERROR;
792: HTNet * net = http->net;
793: HTRequest * request = HTNet_request(net);
1.144 frystyk 794: HTParentAnchor * anchor = HTRequest_anchor(request);
795: HTHost * host = HTNet_host(net);
1.141 frystyk 796:
797: /*
798: ** Check whether we have been interrupted
799: */
800: if (type == HTEvent_BEGIN) {
1.134 frystyk 801: http->next = HTTP_OK;
802: http->result = HT_ERROR;
1.141 frystyk 803: } else if (type == HTEvent_CLOSE) {
1.112 frystyk 804: HTRequest_addError(request, ERR_FATAL, NO, HTERR_INTERRUPTED,
805: NULL, 0, "HTLoadHTTP");
806: HTTPCleanup(request, HT_INTERRUPTED);
1.94 frystyk 807: return HT_OK;
1.141 frystyk 808: } else if (type == HTEvent_END) {
809: HTTPCleanup(request, http->result);
810: return HT_OK;
811: } else if (type == HTEvent_RESET) {
812: HTTPCleanup(request, HT_RECOVER_PIPE);
1.145 frystyk 813: http->state = HTTP_BEGIN;
1.141 frystyk 814: return HT_OK;
815: }
816:
1.71 frystyk 817: /* Now jump into the machine. We know the state from the previous run */
818: while (1) {
819: switch (http->state) {
1.134 frystyk 820: case HTTP_BEGIN:
1.144 frystyk 821: status = HTHost_connect(host, net, HTAnchor_physical(anchor), HTTP_PORT);
822: host = HTNet_host(net);
1.80 frystyk 823: if (status == HT_OK) {
1.140 frystyk 824:
1.123 frystyk 825: /*
1.140 frystyk 826: ** Check the protocol class to see if we have connected to a
827: ** the right class of server, in this case HTTP. If we don't
828: ** know the server then assume a HTTP/1.0
1.123 frystyk 829: */
830: {
831: char * s_class = HTHost_class(host);
1.140 frystyk 832: if (!s_class) {
833: if (HTRequest_proxy(request) == NULL)
834: HTRequest_addConnection(request, "Keep-Alive", "");
835: HTHost_setClass(host, "http");
836: } else if (strcasecomp(s_class, "http")) {
1.123 frystyk 837: HTRequest_addError(request, ERR_FATAL, NO, HTERR_CLASS,
838: NULL, 0, "HTLoadHTTP");
839: http->state = HTTP_ERROR;
840: break;
841: }
1.95 frystyk 842: }
1.147 frystyk 843:
844: if (ConnectionMode & HTTP_NO_PIPELINING) {
845: if (PROT_TRACE) HTTrace("HTTP........ Mode is HTTP/1.1 WITH NO PIPELINING\n");
846: HTRequest_setFlush(request, YES);
847: } else if (ConnectionMode & HTTP_FORCE_10) {
848: if (PROT_TRACE) HTTrace("HTTP........ Mode is FORCE HTTP/1.0\n");
849: HTHost_setVersion(host, HTTP_10);
850: }
851:
852: /* Jump to next state */
1.144 frystyk 853: http->state = HTTP_NEED_STREAM;
854: } else if (status == HT_WOULD_BLOCK || status == HT_PENDING)
855: return HT_OK;
856: else
857: http->state = HTTP_ERROR; /* Error or interrupt */
858: break;
859:
860: case HTTP_NEED_STREAM:
1.138 frystyk 861:
1.144 frystyk 862: #if 0
863: HTChannel_upSemaphore(host->channel);
864: #endif
865:
866: /*
867: ** Create the stream pipe FROM the channel to the application.
868: ** The target for the input stream pipe is set up using the
869: ** stream stack.
870: */
871: {
872: HTStream *me=HTStreamStack(WWW_HTTP,
873: HTRequest_outputFormat(request),
874: HTRequest_outputStream(request),
875: request, YES);
876: HTNet_setReadStream(net, me);
877: HTRequest_setOutputConnected(request, YES);
878: }
1.127 frystyk 879:
1.144 frystyk 880: /*
881: ** Create the stream pipe TO the channel from the application
882: ** and hook it up to the request object
883: */
884: {
885: HTChannel * channel = HTHost_channel(host);
886: HTOutputStream * output = HTChannel_getChannelOStream(channel);
887: int version = HTHost_version(host);
888: HTStream * app = NULL;
889:
1.123 frystyk 890: /*
1.144 frystyk 891: ** Instead of calling this directly we could have a
892: ** stream stack builder on the output stream as well
1.123 frystyk 893: */
1.141 frystyk 894: #ifdef HT_MUX
1.144 frystyk 895: output = (HTOutputStream *)
896: HTBuffer_new(HTMuxWriter_new(host, net, output), request, 512);
1.141 frystyk 897: #endif
898:
1.139 frystyk 899: #ifdef HTTP_DUMP
1.144 frystyk 900: if (PROT_TRACE) {
1.147 frystyk 901: FILE * htfp = NULL;
902: if ((htfp = fopen(HTTP_OUTPUT, "ab")) != NULL) {
1.144 frystyk 903: output = (HTOutputStream *)
1.147 frystyk 904: HTTee((HTStream *) output, HTFWriter_new(request, htfp, NO), NULL);
905: HTTrace("HTTP........ Dumping request to `%s\'\n", HTTP_OUTPUT);
1.144 frystyk 906: }
907: }
1.139 frystyk 908: #endif /* HTTP_DUMP */
1.144 frystyk 909: app = HTMethod_hasEntity(HTRequest_method(request)) ?
910: HTMIMERequest_new(request,
911: HTTPRequest_new(request, (HTStream *) output, NO,
912: version),
913: YES) :
914: HTTPRequest_new(request, (HTStream *) output, YES, version);
915: HTRequest_setInputStream(request, app);
916: }
1.88 frystyk 917:
1.144 frystyk 918: /*
919: ** Set up concurrent read/write if this request isn't the
920: ** source for a PUT or POST. As source we don't start reading
921: ** before all destinations are ready. If destination then
922: ** register the input stream and get ready for read
923: */
924: if (HTRequest_isDestination(request)) {
925: HTHost_register(host, net, HTEvent_READ);
926: HTRequest_linkDestination(request);
927: }
928: http->state = HTTP_CONNECTED;
929: type = HTEvent_WRITE; /* fresh, so try a write */
1.71 frystyk 930: break;
931:
1.87 frystyk 932: /* As we can do simultanous read and write this is now one state */
1.141 frystyk 933: case HTTP_CONNECTED:
934: if (type == HTEvent_WRITE) {
935: if (HTRequest_isDestination(request)) {
936: HTRequest * source = HTRequest_source(request);
937: HTNet * srcnet = HTRequest_net(source);
938: if (srcnet) {
939: HTHost_register(srcnet->host, srcnet, HTEvent_READ);
940: HTHost_unregister(srcnet->host, srcnet, HTEvent_WRITE);
941: }
942: return HT_OK;
943: }
1.126 frystyk 944:
945: /*
946: ** Should we use the input stream directly or call the post
947: ** callback function to send data down to the network?
948: */
949: {
950: HTStream * input = HTRequest_inputStream(request);
951: HTPostCallback * pcbf = HTRequest_postCallback(request);
1.131 frystyk 952: if (pcbf) {
1.139 frystyk 953: if (http->lock)
954: return HT_OK;
955: else {
1.141 frystyk 956: status = (*pcbf)(request, input);
1.140 frystyk 957: if (status == HT_PAUSE || status == HT_LOADED) {
1.141 frystyk 958: type = HTEvent_READ;
1.139 frystyk 959: http->lock = YES;
1.141 frystyk 960: } else if (status==HT_CLOSED)
961: http->state = HTTP_RECOVER_PIPE;
962: else if (status == HT_ERROR) {
1.139 frystyk 963: http->result = HT_INTERRUPTED;
964: http->state = HTTP_ERROR;
965: break;
966: }
967: }
1.131 frystyk 968: } else {
1.142 frystyk 969: /*
970: ** Check to see if we can start a new request
971: ** pending in the host object.
972: */
1.144 frystyk 973: HTHost_launchPending(host);
1.142 frystyk 974: status = HTRequest_flush(request) ?
1.144 frystyk 975: HTHost_forceFlush(host) : (*input->isa->flush)(input);
1.141 frystyk 976: type = HTEvent_READ;
1.131 frystyk 977: }
978: if (status == HT_WOULD_BLOCK) return HT_OK;
1.126 frystyk 979: }
1.141 frystyk 980: } else if (type == HTEvent_FLUSH) {
981: HTStream * input = HTRequest_inputStream(request);
982: if (input == NULL)
983: return HT_ERROR;
984: return (*input->isa->flush)(input);
985: } else if (type == HTEvent_READ) {
1.144 frystyk 986: status = HTHost_read(host, net);
1.131 frystyk 987: if (status == HT_WOULD_BLOCK)
1.94 frystyk 988: return HT_OK;
1.131 frystyk 989: else if (status == HT_CONTINUE) {
1.130 frystyk 990: if (PROT_TRACE) HTTrace("HTTP........ Continuing\n");
1.139 frystyk 991: http->lock = NO;
1.141 frystyk 992: type = HTEvent_WRITE;
1.130 frystyk 993: continue;
1.133 frystyk 994: } else if (status==HT_LOADED)
1.141 frystyk 995: http->state = http->next; /* Jump to next state (OK or ERROR) */
996: else if (status==HT_CLOSED)
997: http->state = HTTP_RECOVER_PIPE;
998: else
1.94 frystyk 999: http->state = HTTP_ERROR;
1.90 frystyk 1000: } else {
1.141 frystyk 1001: http->state = HTTP_ERROR; /* don't know how to handle OOB */
1.90 frystyk 1002: }
1.71 frystyk 1003: break;
1.141 frystyk 1004:
1.134 frystyk 1005: case HTTP_OK:
1.88 frystyk 1006: if (HTRequest_isPostWeb(request)) {
1.91 frystyk 1007: if (HTRequest_isDestination(request)) {
1.126 frystyk 1008: HTRequest * source = HTRequest_source(request);
1.91 frystyk 1009: HTLink *link =
1.127 frystyk 1010: HTLink_find((HTAnchor *)HTRequest_anchor(source),
1.112 frystyk 1011: (HTAnchor *) anchor);
1.109 frystyk 1012: HTLink_setResult(link, HT_LINK_OK);
1.91 frystyk 1013: }
1.112 frystyk 1014: }
1.134 frystyk 1015: HTTPCleanup(request, http->result);
1.94 frystyk 1016: return HT_OK;
1.71 frystyk 1017: break;
1.141 frystyk 1018:
1019: case HTTP_RECOVER_PIPE:
1020: {
1021: /*
1022: ** If this is a persistent connection and we get a close
1023: ** then it is an error and we should recover from it by
1024: ** restarting the pipe line of requests if any
1025: */
1026: if (HTHost_isPersistent(host)) {
1.143 frystyk 1027: if (host == NULL) return HT_ERROR;
1.144 frystyk 1028: HTRequest_setFlush(request, YES);
1029: HTHost_recoverPipe(host);
1030: http->state = HTTP_BEGIN;
1031: HTHost_launchPending(host);
1032: return HT_OK;
1.141 frystyk 1033: } else
1034: http->state = HTTP_OK;
1035: }
1.143 frystyk 1036: break;
1.141 frystyk 1037:
1.71 frystyk 1038: case HTTP_ERROR:
1.143 frystyk 1039: if (HTRequest_isPostWeb(request)) {
1040: if (HTRequest_isDestination(request)) {
1041: HTRequest * source = HTRequest_source(request);
1042: HTLink *link =
1043: HTLink_find((HTAnchor *)HTRequest_anchor(source),
1044: (HTAnchor *) anchor);
1045: HTLink_setResult(link, HT_LINK_ERROR);
1046: }
1047: HTRequest_killPostWeb(request);
1048: }
1049: HTTPCleanup(request, http->result);
1050: return HT_OK;
1051: break;
1052:
1.141 frystyk 1053: default:
1054: HTTrace("bad http state %d.\n", http->state);
1055: HTDebugBreak();
1.71 frystyk 1056: }
1057: } /* End of while(1) */
1058: }
1.88 frystyk 1059:
1.147 frystyk 1060: PUBLIC void HTTP_setConnectionMode (HTTPConnectionMode mode)
1061: {
1062: ConnectionMode = mode;
1063: }
1064:
1065: PUBLIC HTTPConnectionMode HTTP_connectionMode (void)
1066: {
1067: return ConnectionMode;
1068: }
1.21 luotonen 1069:
Webmaster