fixed chunked transfer encoding

Wed, 26 Jun 2013 17:14:45 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 26 Jun 2013 17:14:45 +0200
changeset 80
0de4a90979e1
parent 79
f48cea237ec3
child 81
d25825f37967

fixed chunked transfer encoding

src/server/daemon/httprequest.c file | annotate | diff | comparison | revisions
src/server/daemon/protocol.c file | annotate | diff | comparison | revisions
src/server/util/io.c file | annotate | diff | comparison | revisions
src/server/util/io.h file | annotate | diff | comparison | revisions
--- a/src/server/daemon/httprequest.c	Wed Jun 26 15:09:54 2013 +0200
+++ b/src/server/daemon/httprequest.c	Wed Jun 26 17:14:45 2013 +0200
@@ -684,12 +684,14 @@
                 ret = nsapi_exec(d, sn, rq);
             }
             
-            
-            if(ret != REQ_PROCEED) {
-                fprintf(stderr, "saf not proceed\n");
-            }
             if(ret != REQ_NOACTION) {
-                if(ret == REQ_PROCESSING) {
+                if(ret == REQ_PROCEED) {
+                    /*
+                     * flush buffer and add termination if chunked encoding
+                     * is enabled
+                     */
+                    net_finish(sn->sn.csd);
+                } else if(ret == REQ_PROCESSING) {
                     /* save nsapi context */
                     rq->context.objset_index = i;
 
--- a/src/server/daemon/protocol.c	Wed Jun 26 15:09:54 2013 +0200
+++ b/src/server/daemon/protocol.c	Wed Jun 26 17:14:45 2013 +0200
@@ -333,6 +333,7 @@
         // set stream property
         NetIOStream *stream = (NetIOStream*)sn->csd;
         stream->chunked_enc = 1;
+        rq->rq_attr.chunked = 1;
     }
     
     // add header from rq->srvhdrs
--- a/src/server/util/io.c	Wed Jun 26 15:09:54 2013 +0200
+++ b/src/server/util/io.c	Wed Jun 26 17:14:45 2013 +0200
@@ -47,6 +47,8 @@
     system_write,
     system_writev,
     system_read,
+    NULL,
+    NULL,
     NULL
 };
 
@@ -54,7 +56,9 @@
     (io_write_f)net_stream_write,
     (io_writev_f)net_stream_writev,
     (io_read_f)net_stream_read,
-    (io_sendfile_f)net_stream_sendfile
+    (io_sendfile_f)net_stream_sendfile,
+    (io_close_f)net_stream_close,
+    (io_finish_f)net_stream_finish
 };
 
 
@@ -174,6 +178,16 @@
     return ret;
 }
 
+void net_stream_close(NetIOStream *st) {
+    close(st->fd);
+}
+
+void net_stream_finish(NetIOStream *st) {
+    if(st->chunked_enc) {
+        write(st->fd, "0\r\n\r\n", 5);
+    }
+}
+
 
 ssize_t net_read(SYS_NETFD fd, void *buf, size_t nbytes) {
     ssize_t r = ((IOStream*)fd)->read(fd, buf, nbytes);
@@ -283,6 +297,14 @@
     return IO_ERROR;
 }
 
+void net_close(SYS_NETFD fd) {
+    ((IOStream*)fd)->close(fd);
+}
+
+void net_finish(SYS_NETFD fd) {
+    ((IOStream*)fd)->finish(fd);
+}
+
 
 /* iovec buffer */
 iovec_buf_t *iovec_buf_create(pool_handle_t *pool) {
--- a/src/server/util/io.h	Wed Jun 26 15:09:54 2013 +0200
+++ b/src/server/util/io.h	Wed Jun 26 17:14:45 2013 +0200
@@ -41,12 +41,16 @@
 typedef ssize_t(*io_writev_f)(IOStream *, struct iovec *, int);
 typedef ssize_t(*io_read_f)(IOStream *, void *, size_t);
 typedef ssize_t(*io_sendfile_f)(IOStream *, sendfiledata *);
+typedef void(*io_close_f)(IOStream *);
+typedef void(*io_finish_f)(IOStream *);
 
 struct io_stream {
     io_write_f    write;
     io_writev_f   writev;
     io_read_f     read;
     io_sendfile_f sendfile;
+    io_close_f    close;
+    io_finish_f   finish;
 };
 
 typedef struct SystemIOStream {
@@ -69,7 +73,8 @@
 ssize_t net_write(SYS_NETFD fd, void *buf, size_t nbytes);
 ssize_t net_printf(SYS_NETFD fd, char *format, ...);
 ssize_t net_sendfile(SYS_NETFD fd, sendfiledata *sfd);
-
+void    net_close(SYS_NETFD fd);
+void    net_finish(SYS_NETFD fd);
 
 /* iovec buffer */
 typedef struct iovec_buf{
@@ -94,6 +99,8 @@
 ssize_t net_stream_writev(NetIOStream *st, struct iovec *iovec, int iovcnt);
 ssize_t net_stream_read(NetIOStream *st, void *buf, size_t nbytes);
 ssize_t net_stream_sendfile(NetIOStream *st, sendfiledata *sfd);
+void    net_stream_close(NetIOStream *st);
+void    net_stream_finish(NetIOStream *st);
 
 /* iovec buffer */
 iovec_buf_t *iovec_buf_create(pool_handle_t *pool);

mercurial