16
16
** ======================================================================
18
** Copyright (c) 1996,1997,1998 Ralf S. Engelschall <rse@engelschall.com>
18
** Copyright (c) 1996,1997,1998,1999 Ralf S. Engelschall <rse@engelschall.com>
20
20
** This program is free software; it may be redistributed and/or modified
21
21
** only under the terms of either the Artistic License or the GNU General
37
37
#include "eperl_global.h"
38
38
#include "eperl_proto.h"
40
#define _EPERL_VERSION_C_AS_HEADER_
41
#include "eperl_version.c"
42
#undef _EPERL_VERSION_C_AS_HEADER_
43
46
** print a standard HTTP reponse of header lines
46
void HTTP_PrintResponseHeaders(char *cpBuf)
49
char *HTTP_PrintResponseHeaders(char *cpBuf)
50
if ((cp = getenv("SERVER_PROTOCOL")) == NULL)
52
printf("%s 200 OK\n", cp);
53
if ((strncmp(cpBuf, "HTTP/1.0 ", 9) == 0
54
|| (strncmp(cpBuf, "HTTP/1.1 ", 9) == 0))
55
&& (cpBuf[9] >= '1' && cpBuf[9] <= '5')
56
&& (cpBuf[10] >= '0' && cpBuf[10] <= '9')
57
&& (cpBuf[11] >= '0' && cpBuf[11] <= '9')
59
&& ((cp = strchr(cpBuf + 12, '\n')) != NULL)) {
60
/* found HTTP status code */
61
if (*(cp-1) == '\r') {
65
printf("%s\r\n", cpBuf);
68
/* no HTTP status code */
69
if ((cp = getenv("SERVER_PROTOCOL")) == NULL)
71
printf("%s 200 OK\r\n", cp);
54
74
if (!HTTP_HeaderLineExists(cpBuf, "Server")) {
55
75
if ((cp = getenv("SERVER_SOFTWARE")) == NULL)
56
76
cp = "unknown-server/0.0";
57
printf("Server: %s %s Perl/%s\n", cp, ePerl_WebID, AC_perl_vers);
77
printf("Server: %s %s Perl/%s\r\n", cp, eperl_version.v_web, AC_perl_vers);
60
80
if (!HTTP_HeaderLineExists(cpBuf, "Date"))
61
printf("Date: %s\n", WebTime());
81
printf("Date: %s\r\n", WebTime());
63
83
if (!HTTP_HeaderLineExists(cpBuf, "Connection"))
64
printf("Connection: close\n");
84
printf("Connection: close\r\n");
294
315
/* form the HTTP/1.0 request */
295
sprintf(cmd, "GET %s HTTP/1.0\n", file);
296
sprintf(cmd+strlen(cmd), "Host: %s:%s\n", host, port);
297
sprintf(cmd+strlen(cmd), "User-Agent: %s\n", ePerl_WebID);
298
sprintf(cmd+strlen(cmd), "\n");
316
cmd = malloc(64 + strlen(file) + strlen(host) +
317
strlen(port) + strlen(eperl_version.v_web));
320
/* cmd has enough space */
321
sprintf(cmd, "GET %s HTTP/1.0\r\n", file);
322
sprintf(cmd+strlen(cmd), "Host: %s:%s\r\n", host, port);
323
sprintf(cmd+strlen(cmd), "User-Agent: %s\r\n", eperl_version.v_web);
324
sprintf(cmd+strlen(cmd), "\r\n");
300
326
/* send the request */
301
327
write(s, cmd, strlen(cmd));
303
330
/* convert the file descriptor to a FILE pointer */
304
331
fp = fdopen(s, "r");