Annotation of libwww/Library/src/HTTP.c, revision 1.36
1.1 timbl 1: /* HyperText Tranfer Protocol - Client implementation HTTP.c
2: ** ==========================
1.2 timbl 3: **
4: ** Bugs:
5: ** Not implemented:
6: ** Forward
7: ** Redirection
8: ** Error handling
1.1 timbl 9: */
10:
11: /* Module parameters:
12: ** -----------------
13: **
14: ** These may be undefined and redefined by syspec.h
15: */
1.2 timbl 16:
17: /* Implements:
18: */
19: #include "HTTP.h"
20:
21: #define HTTP_VERSION "HTTP/1.0"
22: #define HTTP2 /* Version is greater than 0.9 */
23:
24: #define INIT_LINE_SIZE 1024 /* Start with line buffer this big */
25: #define LINE_EXTEND_THRESH 256 /* Minimum read size */
26: #define VERSION_LENGTH 20 /* for returned protocol version */
27:
28: /* Uses:
29: */
1.1 timbl 30: #include "HTParse.h"
31: #include "HTUtils.h"
32: #include "tcp.h"
33: #include "HTTCP.h"
34: #include "HTFormat.h"
1.2 timbl 35: #include <ctype.h>
36: #include "HTAlert.h"
37: #include "HTMIME.h"
1.5 timbl 38: #include "HTML.h" /* SCW */
39: #include "HTInit.h" /* SCW */
1.21 luotonen 40: #include "HTAccess.h" /* HTRequest */
1.14 luotonen 41: #include "HTAABrow.h" /* Access Authorization */
1.20 timbl 42: #include "HTTee.h" /* Tee off a cache stream */
43: #include "HTFWriter.h" /* Write to cache file */
1.1 timbl 44:
1.2 timbl 45: struct _HTStream {
46: HTStreamClass * isa; /* all we need to know */
47: };
48:
1.6 timbl 49: extern char * HTAppName; /* Application name: please supply */
50: extern char * HTAppVersion; /* Application version: please supply */
51:
1.19 timbl 52: PUBLIC BOOL HTCacheHTTP = YES; /* Enable caching of HTTP-retrieved files */
1.23 luotonen 53:
54:
1.21 luotonen 55: PRIVATE void parse_401_headers ARGS2(HTRequest *, req,
56: HTInputSocket *, isoc)
57: {
58: HTAAScheme scheme;
59: char *line;
60: int num_schemes = 0;
61: HTList *valid_schemes = HTList_new();
62: HTAssocList **scheme_specifics = NULL;
63: char *template = NULL;
64:
65: /* Read server reply header lines */
66:
67: if (TRACE)
68: fprintf(stderr, "Server 401 reply header lines:\n");
69:
70: while (NULL != (line = HTInputSocket_getUnfoldedLine(isoc)) &&
71: *line != 0) {
72:
73: if (TRACE) fprintf(stderr, "%s\n", line);
74:
75: if (strchr(line, ':')) { /* Valid header line */
76:
77: char *p = line;
78: char *fieldname = HTNextField(&p);
79: char *arg1 = HTNextField(&p);
80: char *args = p;
81:
82: if (0==strcasecomp(fieldname, "WWW-Authenticate:")) {
83: if (HTAA_UNKNOWN != (scheme = HTAAScheme_enum(arg1))) {
84: HTList_addObject(valid_schemes, (void*)scheme);
85: if (!scheme_specifics) {
86: int i;
87: scheme_specifics = (HTAssocList**)
88: malloc(HTAA_MAX_SCHEMES * sizeof(HTAssocList*));
89: if (!scheme_specifics)
90: outofmem(__FILE__, "parse_401_headers");
91: for (i=0; i < HTAA_MAX_SCHEMES; i++)
92: scheme_specifics[i] = NULL;
93: }
94: scheme_specifics[scheme] = HTAA_parseArgList(args);
95: num_schemes++;
96: }
97: else if (TRACE) {
98: fprintf(stderr, "Unknown scheme `%s' %s\n",
99: (arg1 ? arg1 : "(null)"),
100: "in WWW-Authenticate: field");
101: }
102: }
103:
104: else if (0==strcasecomp(fieldname, "WWW-Protection-Template:")) {
105: if (TRACE)
106: fprintf(stderr, "Protection template set to `%s'\n", arg1);
107: StrAllocCopy(template, arg1);
108: }
109:
110: } /* if a valid header line */
111: else if (TRACE) {
112: fprintf(stderr, "Invalid header line `%s' ignored\n", line);
113: } /* else invalid header line */
114: } /* while header lines remain */
115:
116: req->valid_schemes = valid_schemes;
117: req->scheme_specifics = scheme_specifics;
118: req->prot_template = template;
119: }
120:
121:
122:
1.1 timbl 123: /* Load Document from HTTP Server HTLoadHTTP()
124: ** ==============================
125: **
126: ** Given a hypertext address, this routine loads a document.
127: **
128: **
129: ** On entry,
130: ** arg is the hypertext reference of the article to be loaded.
131: **
132: ** On exit,
133: ** returns >=0 If no error, a good socket number
134: ** <0 Error.
135: **
136: ** The socket must be closed by the caller after the document has been
137: ** read.
138: **
139: */
1.19 timbl 140: PUBLIC int HTLoadHTTP ARGS1 (HTRequest *, request)
1.1 timbl 141: {
1.22 luotonen 142: CONST char * arg = NULL;
1.1 timbl 143: int s; /* Socket number for returned data */
144: int status; /* tcp return */
1.10 timbl 145: char crlf[3]; /* A CR LF equivalent string */
1.3 timbl 146: HTStream * target = NULL; /* Unconverted data */
147:
1.2 timbl 148: CONST char* gate = 0; /* disable this feature */
1.1 timbl 149: SockA soc_address; /* Binary network address */
150: SockA * sin = &soc_address;
1.2 timbl 151: BOOL extensions = YES; /* Assume good HTTP server */
1.27 luotonen 152: char * cache_file_name = NULL;
1.17 timbl 153:
1.36 ! frystyk 154: HTCacheHTTP = YES; /* Be sure, that cache is on per default */
! 155:
1.22 luotonen 156: if (request->reason == HTAA_OK_GATEWAY) {
157: arg = request->translated;
1.23 luotonen 158:
159: /*
160: ** Cache lookup
161: */
1.29 luotonen 162: #ifdef NOT_USED_YET
1.27 luotonen 163: if (request->method == METHOD_GET &&
164: !request->authorization &&
165: !request->arg_keywords) {
1.23 luotonen 166:
1.27 luotonen 167: if (HTCacheLookupOrCreate(arg, &cache_file_name)) {
1.23 luotonen 168:
1.27 luotonen 169: FILE * cache_file = fopen(cache_file_name, "r");
1.23 luotonen 170:
1.27 luotonen 171: if (cache_file) {
172: HTFileCopy(cache_file, request->output_stream);
173: fclose(cache_file);
174: free(cache_file_name);
175: (*request->output_stream->isa->free)(request->output_stream);
176: return HT_LOADED;
177: }
178: free(cache_file_name);
179: cache_file_name = NULL;
180: } /* Cache lookup */
181: } /* Can use cache? */
1.29 luotonen 182: #endif /* NOT_USED_YET */
1.27 luotonen 183: } /* I'm a gateway */
1.22 luotonen 184: else {
185: arg = HTAnchor_physical(request->anchor);
1.36 ! frystyk 186: /* No more StrAllocCopy here - moved to HTLoad(). Henrik 14/01-94 */
1.22 luotonen 187: }
188:
1.1 timbl 189: if (!arg) return -3; /* Bad if no name sepcified */
190: if (!*arg) return -2; /* Bad if name had zero length */
191:
192: /* Set up defaults:
193: */
194: #ifdef DECNET
1.2 timbl 195: sin->sdn_family = AF_DECnet; /* Family = DECnet, host order */
196: sin->sdn_objnum = DNP_OBJ; /* Default: http object number */
1.1 timbl 197: #else /* Internet */
1.2 timbl 198: sin->sin_family = AF_INET; /* Family = internet, host order */
199: sin->sin_port = htons(TCP_PORT); /* Default: http port */
1.1 timbl 200: #endif
201:
1.10 timbl 202: sprintf(crlf, "%c%c", CR, LF); /* To be corect on Mac, VM, etc */
203:
1.1 timbl 204: if (TRACE) {
205: if (gate) fprintf(stderr,
206: "HTTPAccess: Using gateway %s for %s\n", gate, arg);
207: else fprintf(stderr, "HTTPAccess: Direct access for %s\n", arg);
208: }
209:
210: /* Get node name and optional port number:
211: */
212: {
213: char *p1 = HTParse(gate ? gate : arg, "", PARSE_HOST);
214: int status = HTParseInet(sin, p1); /* TBL 920622 */
215: free(p1);
216: if (status) return status; /* No such host for example */
217: }
218:
1.15 luotonen 219: /*
220: ** Compose authorization information (this was moved here
221: ** from after the making of the connection so that the connection
222: ** wouldn't have to wait while prompting username and password
223: ** from the user). -- AL 13.10.93
224: */
225: #ifdef ACCESS_AUTH
1.21 luotonen 226: HTAA_composeAuth(request);
227: if (TRACE) {
228: if (request->authorization)
229: fprintf(stderr, "HTTP: Sending Authorization: %s\n",
230: request->authorization);
231: else
232: fprintf(stderr, "HTTP: Not sending authorization (yet)\n");
1.15 luotonen 233: }
234: #endif /* ACCESS_AUTH */
1.1 timbl 235:
1.10 timbl 236: /* Now, let's get a socket set up from the server for the data:
1.1 timbl 237: */
238: #ifdef DECNET
239: s = socket(AF_DECnet, SOCK_STREAM, 0);
240: #else
241: s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
242: #endif
243: status = connect(s, (struct sockaddr*)&soc_address, sizeof(soc_address));
244: if (status < 0) {
245: if (TRACE) fprintf(stderr,
1.30 frystyk 246: "HTTP: Unable to connect to remote host for `%s' (errno = %d).\n",
247: arg, errno);
1.17 timbl 248:
1.1 timbl 249: return HTInetStatus("connect");
250: }
251:
252: if (TRACE) fprintf(stderr, "HTTP connected, socket %d\n", s);
253:
1.17 timbl 254:
255: /* Compose and send command
256: ** ------------------------
257: */
258: {
259: char *command; /* The whole command */
260:
1.1 timbl 261: /* Ask that node for the document,
262: ** omitting the host name & anchor if not gatewayed.
263: */
1.17 timbl 264: if (gate) {
265: command = malloc(4 + strlen(arg)+ 2 + 31);
266: if (command == NULL) outofmem(__FILE__, "HTLoadHTTP");
267: strcpy(command, "GET ");
268: strcat(command, arg);
269: } else { /* not gatewayed */
270: char * p1 = HTParse(arg, "", PARSE_PATH|PARSE_PUNCTUATION);
271: command = malloc(4 + strlen(p1)+ 2 + 31);
272: if (command == NULL) outofmem(__FILE__, "HTLoadHTTP");
1.23 luotonen 273: if (request->method != METHOD_INVALID) {
274: strcpy(command, HTMethod_name(request->method));
1.22 luotonen 275: strcat(command, " ");
276: }
277: else {
278: strcpy(command, "GET ");
279: }
1.17 timbl 280: strcat(command, p1);
281: free(p1);
282: }
1.2 timbl 283: #ifdef HTTP2
1.17 timbl 284: if (extensions) {
285: strcat(command, " ");
286: strcat(command, HTTP_VERSION);
287: }
1.2 timbl 288: #endif
1.17 timbl 289:
290: strcat(command, crlf); /* CR LF, as in rfc 977 */
291:
292: if (extensions) {
1.21 luotonen 293:
1.17 timbl 294: int i;
295: HTAtom * present = WWW_PRESENT;
296: char line[256]; /*@@@@ */
1.21 luotonen 297: HTList *conversions[2];
298:
1.22 luotonen 299: if (!HTConversions) {
300: HTConversions = HTList_new();
1.34 frystyk 301: /* HTFormatInit(HTConversions); App may do this not us tbl940210 */
1.22 luotonen 302: }
1.28 timbl 303:
1.21 luotonen 304: conversions[0] = HTConversions;
305: conversions[1] = request->conversions;
306:
1.34 frystyk 307:
1.21 luotonen 308: for (i=0; i<2; i++) {
309: HTList *cur = conversions[i];
310: HTPresentation *pres;
311:
312: while ((pres = (HTPresentation*)HTList_nextObject(cur))) {
313: if (pres->rep_out == present) {
314: if (pres->quality != 1.0) {
1.35 frystyk 315: sprintf(line, "Accept: %s; q=%.3f%c%c",
1.21 luotonen 316: HTAtom_name(pres->rep),
317: pres->quality, CR, LF);
318: } else {
319: sprintf(line, "Accept: %s%c%c",
320: HTAtom_name(pres->rep), CR, LF);
321: }
322: StrAllocCat(command, line);
1.17 timbl 323: }
324: }
1.2 timbl 325: }
1.22 luotonen 326:
327: sprintf(line, "User-Agent: %s%s %s/%s libwww/%s%c%c",
328: request->user_agent ? request->user_agent : "",
329: request->user_agent ? " VIA Gateway" : "",
1.17 timbl 330: HTAppName ? HTAppName : "unknown",
331: HTAppVersion ? HTAppVersion : "0.0",
332: HTLibraryVersion, CR, LF);
333: StrAllocCat(command, line);
334:
1.22 luotonen 335: if (request->from) {
336: sprintf(line, "From: %s%c%c", request->from, CR, LF);
337: StrAllocCat(command, line);
338: }
339:
1.14 luotonen 340: #ifdef ACCESS_AUTH
1.21 luotonen 341: if (request->authorization != NULL) {
342: sprintf(line, "Authorization: %s%c%c",
343: request->authorization, CR, LF);
1.17 timbl 344: StrAllocCat(command, line);
345: }
346: #endif /* ACCESS_AUTH */
1.22 luotonen 347:
348: if (request->content_type) {
349: sprintf(line, "Content-Type: %s%c%c",
350: HTAtom_name(request->content_type), CR, LF);
351: StrAllocCat(command, line);
352: }
353:
354: if (request->content_length > 0) {
355: sprintf(line, "Content-Length: %d%c%c",
356: request->content_length, CR, LF);
357: StrAllocCat(command, line);
358: }
359:
360:
1.14 luotonen 361: }
1.17 timbl 362:
363: StrAllocCat(command, crlf); /* Blank line means "end" */
364:
365: if (TRACE) fprintf(stderr, "HTTP Tx: %s\n", command);
366:
367: /* Translate into ASCII if necessary
368: */
1.4 timbl 369: #ifdef NOT_ASCII
1.17 timbl 370: {
371: char * p;
372: for(p = command; *p; p++) {
373: *p = TOASCII(*p);
374: }
1.1 timbl 375: }
1.3 timbl 376: #endif
1.17 timbl 377:
378: status = NETWRITE(s, command, (int)strlen(command));
379: free(command);
380: if (status<0) {
381: if (TRACE) fprintf(stderr,
382: "HTTPAccess: Unable to send command.\n");
1.1 timbl 383: return HTInetStatus("send");
1.17 timbl 384: }
385: } /* compose and send command */
386:
1.2 timbl 387:
1.17 timbl 388: /* Read the response
389: ** -----------------
1.11 timbl 390: **
391: ** HTTP0 servers must return ASCII style text, though it can in
392: ** principle be just text without any markup at all.
393: ** Full HTTP servers must return a response
394: ** line and RFC822 style header. The response must therefore in
395: ** either case have a CRLF somewhere soon.
396: **
397: ** This is the theory. In practice, there are (1993) unfortunately
398: ** many binary documents just served up with HTTP0.9. This
399: ** means we have to preserve the binary buffer (on the assumption that
400: ** conversion from ASCII may lose information) in case it turns
401: ** out that we want the binary original.
1.2 timbl 402: */
1.3 timbl 403:
1.22 luotonen 404: if (request->reason == HTAA_OK_GATEWAY) {
1.24 luotonen 405:
1.22 luotonen 406: /*
407: ** Server as a gateway -- send body of the message
408: ** received from client (if any).
409: */
410: if (request->isoc && request->content_length > 0) {
411: int remain = request->content_length;
412: int i = remain;
413: char * buf;
414:
415: while (remain > 0 &&
416: (buf = HTInputSocket_getBlock(request->isoc, &i))) {
417: int status = NETWRITE(s, buf, i);
418: if (status < 0) {
1.27 luotonen 419: CTRACE(stderr, "HTTPAccess.. Unable to forward body\n");
1.22 luotonen 420: return HTInetStatus("send");
421: }
422: remain -= i;
423: i = remain;
424: }
425: }
1.23 luotonen 426:
427: /*
428: ** Cache the document if it a GET request,
429: ** not protected and not a search request.
430: */
1.27 luotonen 431: if (cache_file_name) {
432: FILE * cache_file = fopen(cache_file_name, "w");
1.23 luotonen 433:
1.27 luotonen 434: if (cache_file) {
435: request->output_stream = HTTee(request->output_stream,
1.31 frystyk 436: HTFWriter_new(cache_file, NO));
1.27 luotonen 437: CTRACE(stderr, "Gateway..... writing to cache file\n");
438: }
439: else {
1.29 luotonen 440: #ifdef NOT_USED_YET
1.27 luotonen 441: HTCacheCancel(arg);
1.29 luotonen 442: #endif /* NOT_USED_YET */
1.27 luotonen 443: free(cache_file_name);
444: cache_file_name = NULL;
445: CTRACE(stderr, "Gateway..... couldn't create cache file\n");
1.23 luotonen 446: }
447: }
1.27 luotonen 448: else CTRACE(stderr, "Gateway..... not caching\n");
1.23 luotonen 449:
1.22 luotonen 450: /*
451: ** Load results directly to client
452: */
453: HTCopy(s, request->output_stream);
1.25 luotonen 454: (*request->output_stream->isa->free)(request->output_stream);
1.27 luotonen 455: if (cache_file_name) {
1.29 luotonen 456: #ifdef NOT_USED_YET
1.27 luotonen 457: HTCacheCreated(arg, (time_t)0);
1.29 luotonen 458: #endif /* NOT_USED_YET */
1.27 luotonen 459: free(cache_file_name);
1.24 luotonen 460: }
1.22 luotonen 461: return HT_LOADED;
462: }
463: else { /* read response */
1.21 luotonen 464:
1.17 timbl 465: HTFormat format_in; /* Format arriving in the message */
1.21 luotonen 466: HTInputSocket *isoc = HTInputSocket_new(s);
467: char * status_line = HTInputSocket_getStatusLine(isoc);
1.2 timbl 468:
1.11 timbl 469: /* Kludge to trap binary responses from illegal HTTP0.9 servers.
470: ** First time we have enough, look at the stub in ASCII
471: ** and get out of here if it doesn't look right.
472: **
473: ** We also check for characters above 128 in the first few bytes, and
474: ** if we find them we forget the html default.
475: **
476: ** Bugs: A HTTP0.9 server returning a document starting "HTTP/"
477: ** will be taken as a HTTP 1.0 server. Failure.
478: ** An HTTP 0.9 server returning a binary document with
479: ** characters < 128 will be read as ASCII.
480: */
1.36 ! frystyk 481:
! 482: /* If HTTP 0 response, then DO NOT CACHE (Henrik 14/02-94) */
! 483: if (!status_line) {
1.21 luotonen 484: if (HTInputSocket_seemsBinary(isoc)) {
485: format_in = HTAtom_for("www/unknown");
486: }
487: else {
488: format_in = WWW_HTML;
489: }
1.36 ! frystyk 490: HTCacheHTTP = NO; /* Do not cache */
1.21 luotonen 491: goto copy;
492: } /* end kludge */
493:
494: if (status_line) { /* Decode full HTTP response */
495: /*
496: ** We now have a terminated server status line, and we have
497: ** checked that it is most probably a legal one. Parse it.
498: */
499: char server_version[VERSION_LENGTH+1];
500: int server_status;
501:
502: if (TRACE)
503: fprintf(stderr, "HTTP Status Line: Rx: %.70s\n", status_line);
1.17 timbl 504:
1.21 luotonen 505: sscanf(status_line, "%20s%d", server_version, &server_status);
1.2 timbl 506:
1.21 luotonen 507: format_in = HTAtom_for("www/mime");
1.7 timbl 508:
1.21 luotonen 509: switch (server_status / 100) {
1.2 timbl 510:
1.21 luotonen 511: default: /* bad number */
512: HTAlert("Unknown status reply from server!");
513: break;
1.17 timbl 514:
1.21 luotonen 515: case 3: /* Various forms of redirection */
516: HTAlert(
1.17 timbl 517: "Redirection response from server is not handled by this client");
1.21 luotonen 518: break;
1.17 timbl 519:
1.21 luotonen 520: case 4: /* Access Authorization problem */
1.14 luotonen 521: #ifdef ACCESS_AUTH
1.21 luotonen 522: switch (server_status) {
523: case 401:
524: parse_401_headers(request, isoc);
525:
526: if (TRACE) fprintf(stderr, "%s %d %s\n",
527: "HTTP: close socket", s,
528: "to retry with Access Authorization");
529: HTInputSocket_free(isoc);
530: (void)NETCLOSE(s);
1.24 luotonen 531: if (HTAA_retryWithAuth(request, HTLoadHTTP)) {
1.21 luotonen 532: status = HT_LOADED;/* @@ THIS ONLY WORKS ON LINEMODE */
533: goto clean_up;
534: }
535: /* else falltrough */
536: default:
1.14 luotonen 537: {
1.21 luotonen 538: char *p1 = HTParse(gate ? gate : arg, "",
539: PARSE_HOST);
540: char * message;
541:
542: if (!(message = (char*)malloc(strlen(status_line) +
543: strlen(p1) + 100)))
544: outofmem(__FILE__, "HTTP 4xx status");
1.14 luotonen 545: sprintf(message,
1.21 luotonen 546: "HTTP server at %s replies:\n%s\n\n%s\n",
547: p1, status_line,
548: ((server_status == 401)
549: ? "Access Authorization package giving up.\n"
550: : ""));
1.22 luotonen 551: status = HTLoadError(request, server_status, message);
1.14 luotonen 552: free(message);
553: free(p1);
554: goto clean_up;
555: }
1.21 luotonen 556: } /* switch */
557: goto clean_up;
558: break;
559: #else
560: /* case 4 without Access Authorization falls through */
561: /* to case 5 (previously "I think I goofed"). -- AL */
562: #endif /* ACCESS_AUTH */
563:
564: case 5: /* I think you goofed */
565: {
566: char *p1 = HTParse(gate ? gate : arg, "", PARSE_HOST);
567: char * message = (char*)malloc(strlen(status_line) +
568: strlen(p1) + 100);
569: if (!message) outofmem(__FILE__, "HTTP 5xx status");
570: sprintf(message,
571: "HTTP server at %s replies:\n%s", p1, status_line);
1.22 luotonen 572: status = HTLoadError(request, server_status, message);
1.21 luotonen 573: free(message);
574: free(p1);
575: goto clean_up;
576: }
577: break;
1.17 timbl 578:
1.21 luotonen 579: case 2: /* Good: Got MIME object */
580: break;
1.17 timbl 581:
1.21 luotonen 582: } /* switch on response code */
1.17 timbl 583:
1.21 luotonen 584: } /* Full HTTP reply */
1.17 timbl 585:
586:
1.3 timbl 587: /* Set up the stream stack to handle the body of the message
1.33 timbl 588: **
589: ** In the special case of user asking for source and the message
590: ** being in MIME, we force the MIME decoding to occur, as it is really
591: ** HTTP decoding. If the user really wants the HTTP headers, he
592: ** can ask for them as www/mime.
1.3 timbl 593: */
1.21 luotonen 594:
1.13 duns 595: copy:
1.21 luotonen 596:
1.33 timbl 597: if ((format_in == HTAtom_for("www/mime"))
598: && (request->output_format == HTAtom_for("www/source"))) {
599: target = HTMIMEConvert(request, NULL, format_in,
600: request->output_format, request->output_stream);
601: } else {
602: target = HTStreamStack(format_in, request);
603: }
604:
1.17 timbl 605: if (!target) {
606: char buffer[1024]; /* @@@@@@@@ */
607: sprintf(buffer, "Sorry, no known way of converting %s to %s.",
608: HTAtom_name(format_in), HTAtom_name(request->output_format));
609: fprintf(stderr, "HTTP: %s", buffer);
1.22 luotonen 610: status = HTLoadError(request, 501, buffer);
1.17 timbl 611: goto clean_up;
612: }
613:
1.19 timbl 614: /* @@ Bug: The decision of whether or not to cache should also be
1.21 luotonen 615: ** made contingent on a IP address match or non match.
616: */
1.19 timbl 617: if (HTCacheHTTP) {
618: target = HTTee(target, HTCacheWriter(request, NULL, format_in,
1.21 luotonen 619: request->output_format,
620: request->output_stream));
1.19 timbl 621: }
622:
1.11 timbl 623: /* Push the data down the stream
1.3 timbl 624: ** We have to remember the end of the first buffer we just read
1.2 timbl 625: */
1.30 frystyk 626: if (format_in == WWW_HTML) {
1.17 timbl 627: target = HTNetToText(target); /* Pipe through CR stripper */
628: }
1.21 luotonen 629:
1.17 timbl 630: (*target->isa->put_block)(target,
1.21 luotonen 631: isoc->input_pointer,
632: isoc->input_limit - isoc->input_pointer);
633: HTInputSocket_free(isoc);
1.17 timbl 634: HTCopy(s, target);
635:
636: (*target->isa->free)(target);
637: status = HT_LOADED;
1.11 timbl 638:
1.2 timbl 639: /* Clean up
1.1 timbl 640: */
1.17 timbl 641:
642: clean_up:
643: if (TRACE) fprintf(stderr, "HTTP: close socket %d.\n", s);
644: (void) NETCLOSE(s);
645: return status; /* Good return */
1.3 timbl 646:
1.17 timbl 647: } /* read response */
648: } /* load HTTP */
1.1 timbl 649:
650: /* Protocol descriptor
651: */
652:
1.17 timbl 653: GLOBALDEF PUBLIC HTProtocol HTTP = { "http", HTLoadHTTP, 0, 0 };
1.21 luotonen 654:
Webmaster