fix cgi/lua header parsing
[project/uhttpd.git] / proc.c
diff --git a/proc.c b/proc.c
index e37176d..bbf7ad8 100644 (file)
--- a/proc.c
+++ b/proc.c
 #include "uhttpd.h"
 
 #define __headers \
-       __header(accept) \
-       __header(accept_charset) \
-       __header(accept_encoding) \
-       __header(accept_language) \
-       __header(authorization) \
-       __header(connection) \
-       __header(cookie) \
-       __header(host) \
-       __header(referer) \
-       __header(user_agent) \
-       __header(content_type) \
-       __header(content_length)
+       __header(accept, accept) \
+       __header(accept_charset, accept-charset) \
+       __header(accept_encoding, accept-encoding) \
+       __header(accept_language, accept-language) \
+       __header(authorization, authorization) \
+       __header(connection, connection) \
+       __header(cookie, cookie) \
+       __header(host, host) \
+       __header(referer, referer) \
+       __header(user_agent, user-agent) \
+       __header(content_type, content-type) \
+       __header(content_length, content-length)
 
 #undef __header
 #define __header __enum_header
@@ -147,7 +147,9 @@ struct env_var *uh_get_process_vars(struct client *cl, struct path_info *pi)
        snprintf(redirect_status, sizeof(redirect_status),
                 "%d", req->redirect_status);
        inet_ntop(cl->srv_addr.family, &cl->srv_addr.in, local_addr, sizeof(local_addr));
+       snprintf(local_port, sizeof(local_port), "%d", cl->srv_addr.port);
        inet_ntop(cl->peer_addr.family, &cl->peer_addr.in, remote_addr, sizeof(remote_addr));
+       snprintf(remote_port, sizeof(remote_port), "%d", cl->peer_addr.port);
 
        blobmsg_parse(hdr_policy, __HDR_MAX, tb, blob_data(data), blob_len(data));
        for (i = 0; i < ARRAY_SIZE(proc_header_env); i++) {
@@ -168,7 +170,11 @@ struct env_var *uh_get_process_vars(struct client *cl, struct path_info *pi)
 
 static void proc_close_fds(struct client *cl)
 {
-       close(cl->dispatch.proc.r.sfd.fd.fd);
+       struct dispatch_proc *p = &cl->dispatch.proc;
+
+       close(p->r.sfd.fd.fd);
+       if (p->wrfd.fd >= 0)
+               close(p->wrfd.fd);
 }
 
 static void proc_handle_close(struct relay *r, int ret)
@@ -245,6 +251,16 @@ static void proc_write_cb(struct uloop_fd *fd, unsigned int events)
        client_poll_post_data(cl);
 }
 
+static void proc_relay_write_cb(struct client *cl)
+{
+       struct dispatch_proc *p = &cl->dispatch.proc;
+
+       if (ustream_pending_data(cl->us, true))
+               return;
+
+       ustream_set_read_blocked(&p->r.sfd.stream, false);
+}
+
 static int proc_data_send(struct client *cl, const char *data, int len)
 {
        struct dispatch_proc *p = &cl->dispatch.proc;
@@ -282,8 +298,8 @@ static int proc_data_send(struct client *cl, const char *data, int len)
        return retlen;
 }
 
-bool uh_create_process(struct client *cl, struct path_info *pi,
-                      void (*cb)(struct client *cl, struct path_info *pi))
+bool uh_create_process(struct client *cl, struct path_info *pi, char *url,
+                      void (*cb)(struct client *cl, struct path_info *pi, char *url))
 {
        struct dispatch *d = &cl->dispatch;
        struct dispatch_proc *proc = &d->proc;
@@ -317,7 +333,7 @@ bool uh_create_process(struct client *cl, struct path_info *pi,
                close(wfd[1]);
 
                uh_close_fds();
-               cb(cl, pi);
+               cb(cl, pi, url);
                exit(0);
        }
 
@@ -331,6 +347,7 @@ bool uh_create_process(struct client *cl, struct path_info *pi,
        d->close_fds = proc_close_fds;
        d->data_send = proc_data_send;
        d->data_done = proc_write_close;
+       d->write_cb = proc_relay_write_cb;
        proc->r.header_cb = proc_handle_header;
        proc->r.header_end = proc_handle_header_end;
        proc->r.close = proc_handle_close;