Skip to content

Commit

Permalink
Teach xmosaic about HTTP 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
csev committed Jan 19, 2014
1 parent 37657fb commit 6aa931d
Showing 1 changed file with 33 additions and 1 deletion.
34 changes: 33 additions & 1 deletion libwww/HTTP.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "HTFormat.h"
#include "HTFile.h"

/* #define TRACE 1 */
#define TRACE 1

/* Load Document from HTTP Server HTLoadHTTP()
** ==============================
Expand Down Expand Up @@ -42,6 +42,7 @@ PUBLIC int HTLoadHTTP ARGS4 (CONST char *, arg,
int s; /* Socket number for returned data */
char *command; /* The whole command */
int status; /* tcp return */
char host[256]; /* Hold on to the host */

SockA soc_address; /* Binary network address */
SockA * sin = &soc_address;
Expand Down Expand Up @@ -69,6 +70,7 @@ PUBLIC int HTLoadHTTP ARGS4 (CONST char *, arg,
*/
{
char *p1 = HTParse(gate ? gate : arg, "", PARSE_HOST);
strcpy(host, p1);
int status = HTParseInet(sin, p1); /* TBL 920622 */
free(p1);
if (status) return status; /* No such host for example */
Expand Down Expand Up @@ -119,12 +121,25 @@ PUBLIC int HTLoadHTTP ARGS4 (CONST char *, arg,
strcpy(command, "GET ");
strcat(command, arg);
} else { /* not gatewayed */
/* Switch this to HTTP 1.1 */
char * p1 = HTParse(arg, "", PARSE_PATH|PARSE_PUNCTUATION);
command = malloc(4 + strlen(arg) + 11 + 6 + strlen(host) + 2 + 20 + 2 + 1);
if (command == NULL) outofmem(__FILE__, "HTLoadHTTP");
strcpy(command, "GET ");
strcat(command, arg);
strcat(command, " HTTP/1.1\r\n");
strcat(command, "Host: ");
strcat(command, host);
strcat(command, "\r\n");
strcat(command, "Connection: close\r\n");
/*
char * p1 = HTParse(arg, "", PARSE_PATH|PARSE_PUNCTUATION);
command = malloc(4 + strlen(p1)+ 2 + 1);
if (command == NULL) outofmem(__FILE__, "HTLoadHTTP");
strcpy(command, "GET ");
strcat(command, p1);
free(p1);
*/
}
strcat(command, "\r\n"); /* Include CR for telnet compat. */

Expand All @@ -147,6 +162,23 @@ PUBLIC int HTLoadHTTP ARGS4 (CONST char *, arg,
return HTInetStatus("send");
}

/* Skip the HTTP 1.1 headers */
char buffer[2];
int endhdr = 0;
while ( 1 ) {
int rc = read(s, buffer, 1) ;
if ( TRACE ) fprintf(stderr,"%c",buffer[0]);
if ( rc < 1 ) {
if (TRACE) fprintf(stderr, "HTTPAccess: EOF reading headers.\n");
return HTInetStatus("send");
}
if ( buffer[0] == '\r' && endhdr == 0 ) endhdr = 1;
else if ( buffer[0] == '\n' && endhdr == 1 ) endhdr = 2;
else if ( buffer[0] == '\r' && endhdr == 2 ) endhdr = 3;
else if ( buffer[0] == '\n' && endhdr == 3 ) break;
else endhdr = 0;
}

/* Now load the date
*/

Expand Down

0 comments on commit 6aa931d

Please sign in to comment.