utils: do not emit eof chunk for 204/304 responses
[project/uhttpd.git] / relay.c
diff --git a/relay.c b/relay.c
index 1b55d41..7331a0a 100644 (file)
--- a/relay.c
+++ b/relay.c
@@ -28,6 +28,7 @@ void uh_relay_free(struct relay *r)
        if (r->proc.pending)
                kill(r->proc.pid, SIGKILL);
 
+       uloop_timeout_cancel(&r->timeout);
        uloop_process_delete(&r->proc);
        ustream_free(&r->sfd.stream);
        close(r->sfd.fd.fd);
@@ -55,6 +56,7 @@ static void relay_error(struct relay *r)
        struct ustream *s = &r->sfd.stream;
        int len;
 
+       r->error = true;
        s->eof = true;
        ustream_get_read_buf(s, &len);
        if (len)
@@ -118,7 +120,8 @@ static void relay_read_cb(struct ustream *s, int bytes)
        if (r->process_done)
                uloop_timeout_set(&r->timeout, 1);
 
-       relay_process_headers(r);
+       if (!r->error)
+               relay_process_headers(r);
 
        if (r->header_cb) {
                /*
@@ -139,7 +142,9 @@ static void relay_read_cb(struct ustream *s, int bytes)
        if (!buf || !len)
                return;
 
-       uh_chunk_write(cl, buf, len);
+       if (!r->skip_data)
+               uh_chunk_write(cl, buf, len);
+
        ustream_consume(s, len);
 }