diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2007-08-11 20:20:43 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2007-08-11 20:20:43 +0000 |
commit | 1ec15cd818be3afe9c3f3e1b251937cf119d6add (patch) | |
tree | 30663343cb4ea53e69ba660c5c1803375cb727dd /networking/httpd.c | |
parent | e5d37ccb6e7ea12b61f1063fec13b2e9abbfcb84 (diff) | |
download | busybox-w32-1ec15cd818be3afe9c3f3e1b251937cf119d6add.tar.gz busybox-w32-1ec15cd818be3afe9c3f3e1b251937cf119d6add.tar.bz2 busybox-w32-1ec15cd818be3afe9c3f3e1b251937cf119d6add.zip |
httpd: add support for Status: CGI header
Diffstat (limited to '')
-rw-r--r-- | networking/httpd.c | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/networking/httpd.c b/networking/httpd.c index 7f2594aca..2f76828c6 100644 --- a/networking/httpd.c +++ b/networking/httpd.c | |||
@@ -1043,9 +1043,9 @@ static int sendCgi(const char *url, | |||
1043 | xmove_fd(fromCgi.wr, 1); /* replace stdout with the pipe */ | 1043 | xmove_fd(fromCgi.wr, 1); /* replace stdout with the pipe */ |
1044 | close(fromCgi.rd); | 1044 | close(fromCgi.rd); |
1045 | close(toCgi.wr); | 1045 | close(toCgi.wr); |
1046 | /* Huh? User seeing stderr can be a security problem... | 1046 | /* Huh? User seeing stderr can be a security problem. |
1047 | * and if CGI really wants that, it can always dup2(1,2)... | 1047 | * If CGI really wants that, it can always dup2(1,2). */ |
1048 | * dup2(fromCgi.wr, 2); */ | 1048 | /* dup2(1, 2); */ |
1049 | 1049 | ||
1050 | /* | 1050 | /* |
1051 | * Find PATH_INFO. | 1051 | * Find PATH_INFO. |
@@ -1247,7 +1247,7 @@ static int sendCgi(const char *url, | |||
1247 | post_read_idx = 0; | 1247 | post_read_idx = 0; |
1248 | bodyLen -= count; | 1248 | bodyLen -= count; |
1249 | } else { | 1249 | } else { |
1250 | bodyLen = 0; /* closed */ | 1250 | bodyLen = 0; /* closed */ |
1251 | } | 1251 | } |
1252 | } | 1252 | } |
1253 | 1253 | ||
@@ -1274,32 +1274,43 @@ static int sendCgi(const char *url, | |||
1274 | * CGI may output a few first bytes and then wait | 1274 | * CGI may output a few first bytes and then wait |
1275 | * for POSTDATA without closing stdout. | 1275 | * for POSTDATA without closing stdout. |
1276 | * With full_read we may wait here forever. */ | 1276 | * With full_read we may wait here forever. */ |
1277 | count = safe_read(inFd, rbuf + buf_count, PIPESIZE - 4); | 1277 | count = safe_read(inFd, rbuf + buf_count, PIPESIZE - 8); |
1278 | if (count <= 0) { | 1278 | if (count <= 0) { |
1279 | /* eof (or error) and there was no "HTTP", | 1279 | /* eof (or error) and there was no "HTTP", |
1280 | * so add one and write out the received data */ | 1280 | * so write it, then write received data */ |
1281 | if (buf_count) { | 1281 | if (buf_count) { |
1282 | full_write(s, HTTP_200, sizeof(HTTP_200)-1); | 1282 | full_write(s, HTTP_200, sizeof(HTTP_200)-1); |
1283 | full_write(s, rbuf, buf_count); | 1283 | full_write(s, rbuf, buf_count); |
1284 | } | 1284 | } |
1285 | break; /* closed */ | 1285 | break; /* closed */ |
1286 | } | 1286 | } |
1287 | buf_count += count; | 1287 | buf_count += count; |
1288 | count = 0; | 1288 | count = 0; |
1289 | if (buf_count >= 4) { | 1289 | /* "Status" header format is: "Status: 302 Redirected\r\n" */ |
1290 | /* check to see if CGI added "HTTP" */ | 1290 | if (buf_count >= 8) { |
1291 | if (memcmp(rbuf, "Status: ", 8) == 0) { | ||
1292 | /* send "HTTP/1.0 " */ | ||
1293 | if (full_write(s, HTTP_200, 9) != 9) | ||
1294 | break; | ||
1295 | rbuf += 8; /* skip "Status: " */ | ||
1296 | count -= 8; | ||
1297 | buf_count = -1; /* buffering off */ | ||
1298 | } | ||
1299 | } else if (buf_count >= 4) { | ||
1300 | /* Did CGI add "HTTP"? */ | ||
1291 | if (memcmp(rbuf, HTTP_200, 4) != 0) { | 1301 | if (memcmp(rbuf, HTTP_200, 4) != 0) { |
1292 | /* there is no "HTTP", do it ourself */ | 1302 | /* there is no "HTTP", do it ourself */ |
1293 | if (full_write(s, HTTP_200, sizeof(HTTP_200)-1) != sizeof(HTTP_200)-1) | 1303 | if (full_write(s, HTTP_200, sizeof(HTTP_200)-1) != sizeof(HTTP_200)-1) |
1294 | break; | 1304 | break; |
1295 | } | 1305 | } |
1296 | /* example of valid CGI without "Content-type:" | 1306 | /* Commented out: |
1297 | * echo -en "HTTP/1.0 302 Found\r\n" | ||
1298 | * echo -en "Location: http://www.busybox.net\r\n" | ||
1299 | * echo -en "\r\n" | ||
1300 | if (!strstr(rbuf, "ontent-")) { | 1307 | if (!strstr(rbuf, "ontent-")) { |
1301 | full_write(s, "Content-type: text/plain\r\n\r\n", 28); | 1308 | full_write(s, "Content-type: text/plain\r\n\r\n", 28); |
1302 | } | 1309 | } |
1310 | * Counter-example of valid CGI without Content-type: | ||
1311 | * echo -en "HTTP/1.0 302 Found\r\n" | ||
1312 | * echo -en "Location: http://www.busybox.net\r\n" | ||
1313 | * echo -en "\r\n" | ||
1303 | */ | 1314 | */ |
1304 | count = buf_count; | 1315 | count = buf_count; |
1305 | buf_count = -1; /* buffering off */ | 1316 | buf_count = -1; /* buffering off */ |