Annotation of libwww/Library/src/HTTP.c, revision 1.147
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.147 ! frystyk 6: ** @(#) $Id: HTTP.c,v 1.146 1997年01月29日 19:22:21 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: */
584: HTResponse_setCachable(response, YES);
1.136 frystyk 585: me->target = HTStreamStack(WWW_MIME,
586: HTRequest_outputFormat(request),
587: HTRequest_outputStream(request),
588: request, NO);
1.140 frystyk 589: } else if (me->status==206) {
590: /*
591: ** We got a partial response and now we must check whether
592: ** we issued a cache If-Range request or it was a new
593: ** partial response which we don't have in cache. In the latter
594: ** case, we don't cache the object and in the former we append
595: ** the result to the already existing cache entry.
596: */
597: HTReload reload = HTRequest_reloadMode(request);
598: if (reload == HT_CACHE_RANGE_VALIDATE) {
599: HTResponse_setCachable(response, YES);
600: me->target = HTStreamStack(WWW_MIME_PART,
601: HTRequest_outputFormat(request),
602: HTRequest_outputStream(request),
603: request, NO);
604: } else {
605: me->target = HTStreamStack(WWW_MIME,
606: HTRequest_outputFormat(request),
607: HTRequest_outputStream(request),
608: request, NO);
609: }
1.139 frystyk 610: } else if (me->status==204 || me->status==304) {
1.140 frystyk 611: HTResponse_setCachable(response, YES);
1.136 frystyk 612: me->target = HTStreamStack(WWW_MIME_HEAD,
613: HTRequest_debugFormat(request),
614: HTRequest_debugStream(request),
615: request, NO);
616: } else if (HTRequest_debugStream(request)) {
617: me->target = HTStreamStack(WWW_MIME,
618: HTRequest_debugFormat(request),
619: HTRequest_debugStream(request),
620: request, NO);
621: } else {
1.140 frystyk 622: /*
623: ** We still need to parse the MIME part in order to find any
624: ** valuable meta information which is needed from the response.
625: */
1.136 frystyk 626: me->target = HTStreamStack(WWW_MIME,
627: HTRequest_debugFormat(request),
628: HTRequest_debugStream(request),
629: request, NO);
1.133 frystyk 630: }
1.56 frystyk 631: }
1.113 frystyk 632: if (!me->target) me->target = HTErrorStream();
1.81 frystyk 633: HTTPNextState(me); /* Get next state */
1.80 frystyk 634: me->transparent = YES;
635: return HT_OK;
1.71 frystyk 636: }
1.56 frystyk 637:
1.80 frystyk 638: /*
639: ** Searches for HTTP header line until buffer fills up or a CRLF or LF
640: ** is found
641: */
1.119 frystyk 642: PRIVATE int HTTPStatus_put_block (HTStream * me, const char * b, int l)
1.71 frystyk 643: {
1.146 frystyk 644: me->startLen = me->buflen;
1.80 frystyk 645: while (!me->transparent && l-- > 0) {
646: int status;
647: if (me->target) {
648: if ((status = stream_pipe(me)) != HT_OK)
649: return status;
650: } else {
651: *(me->buffer+me->buflen++) = *b;
652: if (me->state == EOL_FCR) {
653: if (*b == LF) { /* Line found */
654: if ((status = stream_pipe(me)) != HT_OK)
655: return status;
656: } else {
657: me->state = EOL_BEGIN;
658: }
659: } else if (*b == CR) {
660: me->state = EOL_FCR;
661: } else if (*b == LF) {
662: if ((status = stream_pipe(me)) != HT_OK)
663: return status;
1.71 frystyk 664: } else {
1.80 frystyk 665: if (me->buflen >= MAX_STATUS_LEN) {
666: if ((status = stream_pipe(me)) != HT_OK)
667: return status;
668: }
1.71 frystyk 669: }
1.80 frystyk 670: b++;
1.71 frystyk 671: }
1.56 frystyk 672: }
1.99 frystyk 673: if (l > 0) return PUTBLOCK(b, l);
674: return HT_OK;
1.56 frystyk 675: }
676:
1.119 frystyk 677: PRIVATE int HTTPStatus_put_string (HTStream * me, const char * s)
1.71 frystyk 678: {
1.80 frystyk 679: return HTTPStatus_put_block(me, s, (int) strlen(s));
1.71 frystyk 680: }
1.56 frystyk 681:
1.100 frystyk 682: PRIVATE int HTTPStatus_put_character (HTStream * me, char c)
1.71 frystyk 683: {
1.80 frystyk 684: return HTTPStatus_put_block(me, &c, 1);
685: }
686:
1.100 frystyk 687: PRIVATE int HTTPStatus_flush (HTStream * me)
1.80 frystyk 688: {
689: return (*me->target->isa->flush)(me->target);
1.71 frystyk 690: }
691:
1.100 frystyk 692: PRIVATE int HTTPStatus_free (HTStream * me)
1.71 frystyk 693: {
1.87 frystyk 694: int status = HT_OK;
695: if (me->target) {
696: if ((status = (*me->target->isa->_free)(me->target))==HT_WOULD_BLOCK)
697: return HT_WOULD_BLOCK;
698: }
1.115 frystyk 699: HT_FREE(me);
1.100 frystyk 700: return status;
1.71 frystyk 701: }
702:
1.104 frystyk 703: PRIVATE int HTTPStatus_abort (HTStream * me, HTList * e)
1.71 frystyk 704: {
705: if (me->target)
1.74 frystyk 706: ABORT_TARGET;
1.115 frystyk 707: HT_FREE(me);
1.74 frystyk 708: if (PROT_TRACE)
1.116 eric 709: HTTrace("HTTPStatus.. ABORTING...\n");
1.80 frystyk 710: return HT_ERROR;
1.71 frystyk 711: }
712:
713: /* HTTPStatus Stream
714: ** -----------------
715: */
1.119 frystyk 716: PRIVATE const HTStreamClass HTTPStatusClass =
1.71 frystyk 717: {
718: "HTTPStatus",
1.80 frystyk 719: HTTPStatus_flush,
1.71 frystyk 720: HTTPStatus_free,
721: HTTPStatus_abort,
722: HTTPStatus_put_character,
723: HTTPStatus_put_string,
724: HTTPStatus_put_block
725: };
726:
1.113 frystyk 727: PUBLIC HTStream * HTTPStatus_new (HTRequest * request,
728: void * param,
729: HTFormat input_format,
730: HTFormat output_format,
731: HTStream * output_stream)
1.71 frystyk 732: {
1.115 frystyk 733: HTStream * me;
734: if ((me = (HTStream *) HT_CALLOC(1, sizeof(HTStream))) == NULL)
735: HT_OUTOFMEM("HTTPStatus_new");
1.71 frystyk 736: me->isa = &HTTPStatusClass;
1.113 frystyk 737: if (request) {
1.126 frystyk 738: HTNet * net = HTRequest_net(request);
1.125 frystyk 739: /* Get existing copy */
740: http_info * http = (http_info *) HTNet_context(net);
1.113 frystyk 741: me->request = request;
742: me->http = http;
743: http->next = HTTP_ERROR;
744: me->state = EOL_BEGIN;
745: return me;
746: } else
747: return HTErrorStream();
1.71 frystyk 748: }
749:
750: /* ------------------------------------------------------------------------- */
751:
752: /* Load Document from HTTP Server HTLoadHTTP
1.55 frystyk 753: ** ==============================
754: **
755: ** Given a hypertext address, this routine loads a document.
756: **
757: ** On entry,
758: ** request This is the request structure
1.94 frystyk 759: ** returns HT_ERROR Error has occured in call back
760: ** HT_OK Call back was OK
1.55 frystyk 761: */
1.141 frystyk 762: PRIVATE int HTTPEvent (SOCKET soc, void * pVoid, HTEventType type);
763:
764: PUBLIC int HTLoadHTTP (SOCKET soc, HTRequest * request)
1.55 frystyk 765: {
766: http_info *http; /* Specific protocol information */
1.112 frystyk 767: HTParentAnchor *anchor = HTRequest_anchor(request);
1.141 frystyk 768: HTNet * net = HTRequest_net(request);
1.112 frystyk 769:
1.94 frystyk 770: /*
771: ** Initiate a new http structure and bind to request structure
772: ** This is actually state HTTP_BEGIN, but it can't be in the state
773: ** machine as we need the structure first.
774: */
1.141 frystyk 775: if (PROT_TRACE) HTTrace("HTTP........ Looking for `%s\'\n",
776: HTAnchor_physical(anchor));
777: if ((http = (http_info *) HT_CALLOC(1, sizeof(http_info))) == NULL)
778: HT_OUTOFMEM("HTLoadHTTP");
779: http->net = net;
780: HTNet_setContext(net, http);
781: HTNet_setEventCallback(net, HTTPEvent);
782: HTNet_setEventParam(net, http); /* callbacks get http* */
783:
784: return HTTPEvent(soc, http, HTEvent_BEGIN); /* get it started - ops is ignored */
785: }
786:
787: PRIVATE int HTTPEvent (SOCKET soc, void * pVoid, HTEventType type)
788: {
789: http_info * http = (http_info *)pVoid;
790: int status = HT_ERROR;
791: HTNet * net = http->net;
792: HTRequest * request = HTNet_request(net);
1.144 frystyk 793: HTParentAnchor * anchor = HTRequest_anchor(request);
794: HTHost * host = HTNet_host(net);
1.141 frystyk 795:
796: /*
797: ** Check whether we have been interrupted
798: */
799: if (type == HTEvent_BEGIN) {
1.134 frystyk 800: http->next = HTTP_OK;
801: http->result = HT_ERROR;
1.141 frystyk 802: } else if (type == HTEvent_CLOSE) {
1.112 frystyk 803: HTRequest_addError(request, ERR_FATAL, NO, HTERR_INTERRUPTED,
804: NULL, 0, "HTLoadHTTP");
805: HTTPCleanup(request, HT_INTERRUPTED);
1.94 frystyk 806: return HT_OK;
1.141 frystyk 807: } else if (type == HTEvent_END) {
808: HTTPCleanup(request, http->result);
809: return HT_OK;
810: } else if (type == HTEvent_RESET) {
811: HTTPCleanup(request, HT_RECOVER_PIPE);
1.145 frystyk 812: http->state = HTTP_BEGIN;
1.141 frystyk 813: return HT_OK;
814: }
815:
1.71 frystyk 816: /* Now jump into the machine. We know the state from the previous run */
817: while (1) {
818: switch (http->state) {
1.134 frystyk 819: case HTTP_BEGIN:
1.144 frystyk 820: status = HTHost_connect(host, net, HTAnchor_physical(anchor), HTTP_PORT);
821: host = HTNet_host(net);
1.80 frystyk 822: if (status == HT_OK) {
1.140 frystyk 823:
1.123 frystyk 824: /*
1.140 frystyk 825: ** Check the protocol class to see if we have connected to a
826: ** the right class of server, in this case HTTP. If we don't
827: ** know the server then assume a HTTP/1.0
1.123 frystyk 828: */
829: {
830: char * s_class = HTHost_class(host);
1.140 frystyk 831: if (!s_class) {
832: if (HTRequest_proxy(request) == NULL)
833: HTRequest_addConnection(request, "Keep-Alive", "");
834: HTHost_setClass(host, "http");
835: } else if (strcasecomp(s_class, "http")) {
1.123 frystyk 836: HTRequest_addError(request, ERR_FATAL, NO, HTERR_CLASS,
837: NULL, 0, "HTLoadHTTP");
838: http->state = HTTP_ERROR;
839: break;
840: }
1.95 frystyk 841: }
1.147 ! frystyk 842:
! 843: if (ConnectionMode & HTTP_NO_PIPELINING) {
! 844: if (PROT_TRACE) HTTrace("HTTP........ Mode is HTTP/1.1 WITH NO PIPELINING\n");
! 845: HTRequest_setFlush(request, YES);
! 846: } else if (ConnectionMode & HTTP_FORCE_10) {
! 847: if (PROT_TRACE) HTTrace("HTTP........ Mode is FORCE HTTP/1.0\n");
! 848: HTHost_setVersion(host, HTTP_10);
! 849: }
! 850:
! 851: /* Jump to next state */
1.144 frystyk 852: http->state = HTTP_NEED_STREAM;
853: } else if (status == HT_WOULD_BLOCK || status == HT_PENDING)
854: return HT_OK;
855: else
856: http->state = HTTP_ERROR; /* Error or interrupt */
857: break;
858:
859: case HTTP_NEED_STREAM:
1.138 frystyk 860:
1.144 frystyk 861: #if 0
862: HTChannel_upSemaphore(host->channel);
863: #endif
864:
865: /*
866: ** Create the stream pipe FROM the channel to the application.
867: ** The target for the input stream pipe is set up using the
868: ** stream stack.
869: */
870: {
871: HTStream *me=HTStreamStack(WWW_HTTP,
872: HTRequest_outputFormat(request),
873: HTRequest_outputStream(request),
874: request, YES);
875: HTNet_setReadStream(net, me);
876: HTRequest_setOutputConnected(request, YES);
877: }
1.127 frystyk 878:
1.144 frystyk 879: /*
880: ** Create the stream pipe TO the channel from the application
881: ** and hook it up to the request object
882: */
883: {
884: HTChannel * channel = HTHost_channel(host);
885: HTOutputStream * output = HTChannel_getChannelOStream(channel);
886: int version = HTHost_version(host);
887: HTStream * app = NULL;
888:
1.123 frystyk 889: /*
1.144 frystyk 890: ** Instead of calling this directly we could have a
891: ** stream stack builder on the output stream as well
1.123 frystyk 892: */
1.141 frystyk 893: #ifdef HT_MUX
1.144 frystyk 894: output = (HTOutputStream *)
895: HTBuffer_new(HTMuxWriter_new(host, net, output), request, 512);
1.141 frystyk 896: #endif
897:
1.139 frystyk 898: #ifdef HTTP_DUMP
1.144 frystyk 899: if (PROT_TRACE) {
1.147 ! frystyk 900: FILE * htfp = NULL;
! 901: if ((htfp = fopen(HTTP_OUTPUT, "ab")) != NULL) {
1.144 frystyk 902: output = (HTOutputStream *)
1.147 ! frystyk 903: HTTee((HTStream *) output, HTFWriter_new(request, htfp, NO), NULL);
! 904: HTTrace("HTTP........ Dumping request to `%s\'\n", HTTP_OUTPUT);
1.144 frystyk 905: }
906: }
1.139 frystyk 907: #endif /* HTTP_DUMP */
1.144 frystyk 908: app = HTMethod_hasEntity(HTRequest_method(request)) ?
909: HTMIMERequest_new(request,
910: HTTPRequest_new(request, (HTStream *) output, NO,
911: version),
912: YES) :
913: HTTPRequest_new(request, (HTStream *) output, YES, version);
914: HTRequest_setInputStream(request, app);
915: }
1.88 frystyk 916:
1.144 frystyk 917: /*
918: ** Set up concurrent read/write if this request isn't the
919: ** source for a PUT or POST. As source we don't start reading
920: ** before all destinations are ready. If destination then
921: ** register the input stream and get ready for read
922: */
923: if (HTRequest_isDestination(request)) {
924: HTHost_register(host, net, HTEvent_READ);
925: HTRequest_linkDestination(request);
926: }
927: http->state = HTTP_CONNECTED;
928: type = HTEvent_WRITE; /* fresh, so try a write */
1.71 frystyk 929: break;
930:
1.87 frystyk 931: /* As we can do simultanous read and write this is now one state */
1.141 frystyk 932: case HTTP_CONNECTED:
933: if (type == HTEvent_WRITE) {
934: if (HTRequest_isDestination(request)) {
935: HTRequest * source = HTRequest_source(request);
936: HTNet * srcnet = HTRequest_net(source);
937: if (srcnet) {
938: HTHost_register(srcnet->host, srcnet, HTEvent_READ);
939: HTHost_unregister(srcnet->host, srcnet, HTEvent_WRITE);
940: }
941: return HT_OK;
942: }
1.126 frystyk 943:
944: /*
945: ** Should we use the input stream directly or call the post
946: ** callback function to send data down to the network?
947: */
948: {
949: HTStream * input = HTRequest_inputStream(request);
950: HTPostCallback * pcbf = HTRequest_postCallback(request);
1.131 frystyk 951: if (pcbf) {
1.139 frystyk 952: if (http->lock)
953: return HT_OK;
954: else {
1.141 frystyk 955: status = (*pcbf)(request, input);
1.140 frystyk 956: if (status == HT_PAUSE || status == HT_LOADED) {
1.141 frystyk 957: type = HTEvent_READ;
1.139 frystyk 958: http->lock = YES;
1.141 frystyk 959: } else if (status==HT_CLOSED)
960: http->state = HTTP_RECOVER_PIPE;
961: else if (status == HT_ERROR) {
1.139 frystyk 962: http->result = HT_INTERRUPTED;
963: http->state = HTTP_ERROR;
964: break;
965: }
966: }
1.131 frystyk 967: } else {
1.142 frystyk 968: /*
969: ** Check to see if we can start a new request
970: ** pending in the host object.
971: */
1.144 frystyk 972: HTHost_launchPending(host);
1.142 frystyk 973: status = HTRequest_flush(request) ?
1.144 frystyk 974: HTHost_forceFlush(host) : (*input->isa->flush)(input);
1.141 frystyk 975: type = HTEvent_READ;
1.131 frystyk 976: }
977: if (status == HT_WOULD_BLOCK) return HT_OK;
1.126 frystyk 978: }
1.141 frystyk 979: } else if (type == HTEvent_FLUSH) {
980: HTStream * input = HTRequest_inputStream(request);
981: if (input == NULL)
982: return HT_ERROR;
983: return (*input->isa->flush)(input);
984: } else if (type == HTEvent_READ) {
1.144 frystyk 985: status = HTHost_read(host, net);
1.131 frystyk 986: if (status == HT_WOULD_BLOCK)
1.94 frystyk 987: return HT_OK;
1.131 frystyk 988: else if (status == HT_CONTINUE) {
1.130 frystyk 989: if (PROT_TRACE) HTTrace("HTTP........ Continuing\n");
1.139 frystyk 990: http->lock = NO;
1.141 frystyk 991: type = HTEvent_WRITE;
1.130 frystyk 992: continue;
1.133 frystyk 993: } else if (status==HT_LOADED)
1.141 frystyk 994: http->state = http->next; /* Jump to next state (OK or ERROR) */
995: else if (status==HT_CLOSED)
996: http->state = HTTP_RECOVER_PIPE;
997: else
1.94 frystyk 998: http->state = HTTP_ERROR;
1.90 frystyk 999: } else {
1.141 frystyk 1000: http->state = HTTP_ERROR; /* don't know how to handle OOB */
1.90 frystyk 1001: }
1.71 frystyk 1002: break;
1.141 frystyk 1003:
1.134 frystyk 1004: case HTTP_OK:
1.88 frystyk 1005: if (HTRequest_isPostWeb(request)) {
1.91 frystyk 1006: if (HTRequest_isDestination(request)) {
1.126 frystyk 1007: HTRequest * source = HTRequest_source(request);
1.91 frystyk 1008: HTLink *link =
1.127 frystyk 1009: HTLink_find((HTAnchor *)HTRequest_anchor(source),
1.112 frystyk 1010: (HTAnchor *) anchor);
1.109 frystyk 1011: HTLink_setResult(link, HT_LINK_OK);
1.91 frystyk 1012: }
1.112 frystyk 1013: }
1.134 frystyk 1014: HTTPCleanup(request, http->result);
1.94 frystyk 1015: return HT_OK;
1.71 frystyk 1016: break;
1.141 frystyk 1017:
1018: case HTTP_RECOVER_PIPE:
1019: {
1020: /*
1021: ** If this is a persistent connection and we get a close
1022: ** then it is an error and we should recover from it by
1023: ** restarting the pipe line of requests if any
1024: */
1025: if (HTHost_isPersistent(host)) {
1.143 frystyk 1026: if (host == NULL) return HT_ERROR;
1.144 frystyk 1027: HTRequest_setFlush(request, YES);
1028: HTHost_recoverPipe(host);
1029: http->state = HTTP_BEGIN;
1030: HTHost_launchPending(host);
1031: return HT_OK;
1.141 frystyk 1032: } else
1033: http->state = HTTP_OK;
1034: }
1.143 frystyk 1035: break;
1.141 frystyk 1036:
1.71 frystyk 1037: case HTTP_ERROR:
1.143 frystyk 1038: if (HTRequest_isPostWeb(request)) {
1039: if (HTRequest_isDestination(request)) {
1040: HTRequest * source = HTRequest_source(request);
1041: HTLink *link =
1042: HTLink_find((HTAnchor *)HTRequest_anchor(source),
1043: (HTAnchor *) anchor);
1044: HTLink_setResult(link, HT_LINK_ERROR);
1045: }
1046: HTRequest_killPostWeb(request);
1047: }
1048: HTTPCleanup(request, http->result);
1049: return HT_OK;
1050: break;
1051:
1.141 frystyk 1052: default:
1053: HTTrace("bad http state %d.\n", http->state);
1054: HTDebugBreak();
1.71 frystyk 1055: }
1056: } /* End of while(1) */
1057: }
1.88 frystyk 1058:
1.147 ! frystyk 1059: PUBLIC void HTTP_setConnectionMode (HTTPConnectionMode mode)
! 1060: {
! 1061: ConnectionMode = mode;
! 1062: }
! 1063:
! 1064: PUBLIC HTTPConnectionMode HTTP_connectionMode (void)
! 1065: {
! 1066: return ConnectionMode;
! 1067: }
1.21 luotonen 1068:
Webmaster