summaryrefslogtreecommitdiffhomepage
path: root/contrib/package/uhttpd/src/uhttpd-file.c
diff options
context:
space:
mode:
authorJo-Philipp Wich <jow@openwrt.org>2010-03-20 13:45:50 +0000
committerJo-Philipp Wich <jow@openwrt.org>2010-03-20 13:45:50 +0000
commit0f18174879e121e5c5a64de0e3cb88a9c78e2b37 (patch)
treeb6baf4fa1aacd49304075b00765e70c8ff0eb3fe /contrib/package/uhttpd/src/uhttpd-file.c
parent66ffcefa5555b35fc2e71429d9be16ac6de82801 (diff)
uhttpd:
- rework url parsing and path resolving - handle more cgi quirks - change request dispatching - clean up cflags
Diffstat (limited to 'contrib/package/uhttpd/src/uhttpd-file.c')
-rw-r--r--contrib/package/uhttpd/src/uhttpd-file.c101
1 files changed, 46 insertions, 55 deletions
diff --git a/contrib/package/uhttpd/src/uhttpd-file.c b/contrib/package/uhttpd/src/uhttpd-file.c
index c0e353a8e..c300f0e45 100644
--- a/contrib/package/uhttpd/src/uhttpd-file.c
+++ b/contrib/package/uhttpd/src/uhttpd-file.c
@@ -2,8 +2,8 @@
#define _BSD_SOURCE /* scandir() ... */
#include "uhttpd.h"
-#include "uhttpd-file.h"
#include "uhttpd-utils.h"
+#include "uhttpd-file.h"
#include "uhttpd-mimetypes.h"
@@ -296,40 +296,38 @@ static void uh_file_dirlist(struct client *cl, struct http_request *req, struct
}
-void uh_file_request(struct client *cl, struct http_request *req)
+void uh_file_request(struct client *cl, struct http_request *req, struct uh_path_info *pi)
{
int fd, rlen;
char buf[UH_LIMIT_MSGHEAD];
- struct uh_path_info *pi;
- /* obtain path information */
- if( (pi = uh_path_lookup(cl, req->url)) != NULL )
+ /* we have a file */
+ if( (pi->stat.st_mode & S_IFREG) && ((fd = open(pi->phys, O_RDONLY)) > 0) )
{
- /* we have a file */
- if( (pi->stat.st_mode & S_IFREG) &&
- ((fd = open(pi->phys, O_RDONLY)) > 0)
+ /* test preconditions */
+ if(
+ uh_file_if_modified_since(cl, req, &pi->stat) &&
+ uh_file_if_match(cl, req, &pi->stat) &&
+ uh_file_if_range(cl, req, &pi->stat) &&
+ uh_file_if_unmodified_since(cl, req, &pi->stat) &&
+ uh_file_if_none_match(cl, req, &pi->stat)
) {
- /* test preconditions */
- if(
- uh_file_if_modified_since(cl, req, &pi->stat) &&
- uh_file_if_match(cl, req, &pi->stat) &&
- uh_file_if_range(cl, req, &pi->stat) &&
- uh_file_if_unmodified_since(cl, req, &pi->stat) &&
- uh_file_if_none_match(cl, req, &pi->stat)
- ) {
- /* write status */
- uh_file_response_200(cl, req, &pi->stat);
-
- uh_http_sendf(cl, NULL, "Content-Type: %s\r\n", uh_file_mime_lookup(pi->name));
- uh_http_sendf(cl, NULL, "Content-Length: %i\r\n", pi->stat.st_size);
-
- /* if request was HTTP 1.1 we'll respond chunked */
- if( req->version > 1.0 )
- uh_http_send(cl, NULL, "Transfer-Encoding: chunked\r\n", -1);
-
- /* close header */
- uh_http_send(cl, NULL, "\r\n", -1);
+ /* write status */
+ uh_file_response_200(cl, req, &pi->stat);
+
+ uh_http_sendf(cl, NULL, "Content-Type: %s\r\n", uh_file_mime_lookup(pi->name));
+ uh_http_sendf(cl, NULL, "Content-Length: %i\r\n", pi->stat.st_size);
+
+ /* if request was HTTP 1.1 we'll respond chunked */
+ if( (req->version > 1.0) && (req->method != UH_HTTP_MSG_HEAD) )
+ uh_http_send(cl, NULL, "Transfer-Encoding: chunked\r\n", -1);
+ /* close header */
+ uh_http_send(cl, NULL, "\r\n", -1);
+
+ /* send body */
+ if( req->method != UH_HTTP_MSG_HEAD )
+ {
/* pump file data */
while( (rlen = read(fd, buf, sizeof(buf))) > 0 )
{
@@ -339,44 +337,37 @@ void uh_file_request(struct client *cl, struct http_request *req)
/* send trailer in chunked mode */
uh_http_send(cl, req, "", 0);
}
-
- /* one of the preconditions failed, terminate opened header and exit */
- else
- {
- uh_http_send(cl, NULL, "\r\n", -1);
- }
-
- close(fd);
}
- /* directory */
- else if( pi->stat.st_mode & S_IFDIR )
+ /* one of the preconditions failed, terminate opened header and exit */
+ else
{
- /* write status */
- uh_file_response_200(cl, req, NULL);
+ uh_http_send(cl, NULL, "\r\n", -1);
+ }
- if( req->version > 1.0 )
- uh_http_send(cl, NULL, "Transfer-Encoding: chunked\r\n", -1);
+ close(fd);
+ }
- uh_http_send(cl, NULL, "Content-Type: text/html\r\n\r\n", -1);
+ /* directory */
+ else if( pi->stat.st_mode & S_IFDIR )
+ {
+ /* write status */
+ uh_file_response_200(cl, req, NULL);
- /* content */
- uh_file_dirlist(cl, req, pi);
- }
+ if( req->version > 1.0 )
+ uh_http_send(cl, NULL, "Transfer-Encoding: chunked\r\n", -1);
- /* 403 */
- else
- {
- uh_http_sendhf(cl, 403, "Forbidden",
- "Access to this resource is forbidden");
- }
+ uh_http_send(cl, NULL, "Content-Type: text/html\r\n\r\n", -1);
+
+ /* content */
+ uh_file_dirlist(cl, req, pi);
}
- /* 404 */
+ /* 403 */
else
{
- uh_http_sendhf(cl, 404, "Not Found",
- "No such file or directory");
+ uh_http_sendhf(cl, 403, "Forbidden",
+ "Access to this resource is forbidden");
}
}