mirror of https://github.com/nealey/eris.git
Super dumb CONNECT handling
This commit is contained in:
parent
68452c56fa
commit
86757101eb
25
eris.c
25
eris.c
|
@ -85,6 +85,7 @@ int doidx = 0;
|
||||||
int nochdir = 0;
|
int nochdir = 0;
|
||||||
int redirect = 0;
|
int redirect = 0;
|
||||||
int portappend = 0;
|
int portappend = 0;
|
||||||
|
char *connector = NULL;
|
||||||
|
|
||||||
|
|
||||||
/* Variables that persist between requests */
|
/* Variables that persist between requests */
|
||||||
|
@ -98,7 +99,7 @@ char *remote_ident = NULL;
|
||||||
* These could be put into a struct for a threading version
|
* These could be put into a struct for a threading version
|
||||||
* of eris.
|
* of eris.
|
||||||
*/
|
*/
|
||||||
enum { GET, POST, HEAD } method;
|
enum { GET, POST, HEAD, CONNECT } method;
|
||||||
char *host;
|
char *host;
|
||||||
char *user_agent;
|
char *user_agent;
|
||||||
char *refer;
|
char *refer;
|
||||||
|
@ -230,7 +231,7 @@ parse_options(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int opt;
|
int opt;
|
||||||
|
|
||||||
while (-1 != (opt = getopt(argc, argv, "acdhkprv."))) {
|
while (-1 != (opt = getopt(argc, argv, "acdhkpro:v."))) {
|
||||||
switch (opt) {
|
switch (opt) {
|
||||||
case 'a':
|
case 'a':
|
||||||
doauth = 1;
|
doauth = 1;
|
||||||
|
@ -250,6 +251,9 @@ parse_options(int argc, char *argv[])
|
||||||
case 'r':
|
case 'r':
|
||||||
redirect = 1;
|
redirect = 1;
|
||||||
break;
|
break;
|
||||||
|
case 'o':
|
||||||
|
connector = optarg;
|
||||||
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
printf("%s\n", FNORD);
|
printf("%s\n", FNORD);
|
||||||
exit(0);
|
exit(0);
|
||||||
|
@ -264,6 +268,7 @@ parse_options(int argc, char *argv[])
|
||||||
fprintf(stderr, "-. Serve out of ./ (no vhosting)\n");
|
fprintf(stderr, "-. Serve out of ./ (no vhosting)\n");
|
||||||
fprintf(stderr, "-p Append port to hostname directory\n");
|
fprintf(stderr, "-p Append port to hostname directory\n");
|
||||||
fprintf(stderr, "-r Enable symlink redirection\n");
|
fprintf(stderr, "-r Enable symlink redirection\n");
|
||||||
|
fprintf(stderr, "-o HANDLER Path to HTTP CONNECT handler\n");
|
||||||
fprintf(stderr, "-v Print version and exit\n");
|
fprintf(stderr, "-v Print version and exit\n");
|
||||||
exit(69);
|
exit(69);
|
||||||
}
|
}
|
||||||
|
@ -768,13 +773,16 @@ handle_request()
|
||||||
}
|
}
|
||||||
if (!strncmp(request, "GET /", 5)) {
|
if (!strncmp(request, "GET /", 5)) {
|
||||||
method = GET;
|
method = GET;
|
||||||
p = request + 5;
|
p = request + 4;
|
||||||
} else if (!strncmp(request, "POST /", 6)) {
|
} else if (!strncmp(request, "POST /", 6)) {
|
||||||
method = POST;
|
method = POST;
|
||||||
p = request + 6;
|
p = request + 5;
|
||||||
} else if (!strncmp(request, "HEAD /", 6)) {
|
} else if (!strncmp(request, "HEAD /", 6)) {
|
||||||
method = HEAD;
|
method = HEAD;
|
||||||
p = request + 6;
|
p = request + 5;
|
||||||
|
} else if (connector && !strncmp(request, "CONNECT ", 8)) {
|
||||||
|
method = CONNECT;
|
||||||
|
p = request + 8;
|
||||||
} else {
|
} else {
|
||||||
/* This also handles the case where fgets does nothing */
|
/* This also handles the case where fgets does nothing */
|
||||||
badrequest(405, "Method Not Allowed", "Unsupported HTTP method.");
|
badrequest(405, "Method Not Allowed", "Unsupported HTTP method.");
|
||||||
|
@ -786,7 +794,7 @@ handle_request()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Interpret path into fspath. */
|
/* Interpret path into fspath. */
|
||||||
path = p - 1;
|
path = p;
|
||||||
{
|
{
|
||||||
char *fsp = fspath;
|
char *fsp = fspath;
|
||||||
char *query_string = NULL;
|
char *query_string = NULL;
|
||||||
|
@ -975,6 +983,11 @@ handle_request()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (method == CONNECT) {
|
||||||
|
execl(connector, connector, path, NULL);
|
||||||
|
badrequest(500, "Unable to exec connector", strerror(errno));
|
||||||
|
}
|
||||||
|
|
||||||
/* Serve the file */
|
/* Serve the file */
|
||||||
alarm(WRITETIMEOUT);
|
alarm(WRITETIMEOUT);
|
||||||
find_serve_file(fspath);
|
find_serve_file(fspath);
|
||||||
|
|
5
test.sh
5
test.sh
|
@ -266,6 +266,11 @@ title "Read timeout"
|
||||||
(sleep 2.1; printf 'GET / HTTP/1.0\r\n\r\n') | $HTTPD 2>/dev/null | grep -q '.' && fail || pass
|
(sleep 2.1; printf 'GET / HTTP/1.0\r\n\r\n') | $HTTPD 2>/dev/null | grep -q '.' && fail || pass
|
||||||
|
|
||||||
|
|
||||||
|
H "CONNECT handler"
|
||||||
|
|
||||||
|
title "Basic test"
|
||||||
|
printf 'CONNECT /etc HTTP/1.1\r\n\r\n' | $HTTPD -o /bin/ls | grep -q passwd && pass || fail
|
||||||
|
|
||||||
|
|
||||||
H "fnord bugs"
|
H "fnord bugs"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue