mirror of https://github.com/nealey/eris.git
ready to serve files
This commit is contained in:
parent
78ec64f506
commit
b12721e22a
41
eris.c
41
eris.c
|
@ -59,8 +59,8 @@
|
||||||
/* Maximum size of a request line */
|
/* Maximum size of a request line */
|
||||||
#define MAXREQUESTLEN 2048
|
#define MAXREQUESTLEN 2048
|
||||||
|
|
||||||
/* Maximum number of headers */
|
/* Maximum number of header fields */
|
||||||
#define MAXHEADERS 40
|
#define MAXHEADERFIELDS 60
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Options
|
* Options
|
||||||
|
@ -169,8 +169,9 @@ badrequest(long code, const char *httpcomment, const char *message)
|
||||||
size_t
|
size_t
|
||||||
extract_header_field(char *buf, char **val, int cgi)
|
extract_header_field(char *buf, char **val, int cgi)
|
||||||
{
|
{
|
||||||
size_t pos = 0; /* Input */
|
size_t len;
|
||||||
size_t len = 0; /* Output */
|
|
||||||
|
*val = NULL;
|
||||||
|
|
||||||
for (len = 0; buf[len]; len += 1) {
|
for (len = 0; buf[len]; len += 1) {
|
||||||
if (! *val) {
|
if (! *val) {
|
||||||
|
@ -568,7 +569,6 @@ handle_request()
|
||||||
char request[MAXREQUESTLEN];
|
char request[MAXREQUESTLEN];
|
||||||
char fspath[MAXREQUESTLEN];
|
char fspath[MAXREQUESTLEN];
|
||||||
char buf[MAXHEADERLEN];
|
char buf[MAXHEADERLEN];
|
||||||
char *env[MAXHEADERS + 1];
|
|
||||||
char *p;
|
char *p;
|
||||||
char *query_string = NULL;
|
char *query_string = NULL;
|
||||||
int method;
|
int method;
|
||||||
|
@ -659,7 +659,7 @@ handle_request()
|
||||||
/* Read header fields */
|
/* Read header fields */
|
||||||
{
|
{
|
||||||
char *base = buf;
|
char *base = buf;
|
||||||
size_t nheaders = 0;
|
int nheaders = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
char *cgi_name = base;
|
char *cgi_name = base;
|
||||||
|
@ -672,7 +672,7 @@ handle_request()
|
||||||
if (plen < 40) {
|
if (plen < 40) {
|
||||||
badrequest(431, "Request Header Too Large", "The HTTP header block was too large");
|
badrequest(431, "Request Header Too Large", "The HTTP header block was too large");
|
||||||
}
|
}
|
||||||
if (nheaders >= MAXHEADERS) {
|
if (nheaders++ >= MAXHEADERFIELDS) {
|
||||||
badrequest(431, "Request Header Too Large", "Too many HTTP Headers");
|
badrequest(431, "Request Header Too Large", "Too many HTTP Headers");
|
||||||
}
|
}
|
||||||
strcpy(cgi_name, "HTTP_");
|
strcpy(cgi_name, "HTTP_");
|
||||||
|
@ -694,6 +694,11 @@ handle_request()
|
||||||
badrequest(400, "Invalid header", "Unable to parse header block");
|
badrequest(400, "Invalid header", "Unable to parse header block");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set up CGI environment variables */
|
||||||
|
setenv(cgi_name, val, 1);
|
||||||
|
|
||||||
|
/* Handle special header fields */
|
||||||
|
base = name + len + 1;
|
||||||
if (! strcmp(name, "HOST")) {
|
if (! strcmp(name, "HOST")) {
|
||||||
host = val;
|
host = val;
|
||||||
} else if (! strcmp(name, "USER_AGENT")) {
|
} else if (! strcmp(name, "USER_AGENT")) {
|
||||||
|
@ -708,25 +713,12 @@ handle_request()
|
||||||
}
|
}
|
||||||
} else if (! strcmp(name, "IF_MODIFIED_SINCE")) {
|
} else if (! strcmp(name, "IF_MODIFIED_SINCE")) {
|
||||||
ims = timerfc(val);
|
ims = timerfc(val);
|
||||||
|
} else {
|
||||||
|
/* We can re-use this buffer space */
|
||||||
|
base = cgi_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set up CGI environment variables */
|
|
||||||
{
|
|
||||||
char *d = name + strlen(name);
|
|
||||||
char *s = val;
|
|
||||||
|
|
||||||
*(d++) = '=';
|
|
||||||
while (*s) {
|
|
||||||
*(d++) = *(s++);
|
|
||||||
}
|
}
|
||||||
*d = '\0';
|
|
||||||
DUMP_s(cgi_name);
|
|
||||||
|
|
||||||
env[nheaders++] = cgi_name;
|
|
||||||
base = d + 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
env[nheaders] = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try to change into the appropriate directory */
|
/* Try to change into the appropriate directory */
|
||||||
|
@ -753,6 +745,9 @@ handle_request()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Serve the file */
|
||||||
|
execl("/bin/sh", "sh", "-c", "set", NULL);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue