add handler for http expect header webdav

Sun, 19 Jan 2020 09:01:39 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 19 Jan 2020 09:01:39 +0100
branch
webdav
changeset 235
4990147c58d0
parent 234
f30740c3aafb
child 236
e81d3e517b57

add handler for http expect header

src/server/daemon/httprequest.c file | annotate | diff | comparison | revisions
src/server/daemon/protocol.c file | annotate | diff | comparison | revisions
src/server/daemon/protocol.h file | annotate | diff | comparison | revisions
src/server/util/io.c file | annotate | diff | comparison | revisions
src/server/webdav/webdav.c file | annotate | diff | comparison | revisions
--- a/src/server/daemon/httprequest.c	Sat Jan 18 16:48:03 2020 +0100
+++ b/src/server/daemon/httprequest.c	Sun Jan 19 09:01:39 2020 +0100
@@ -945,7 +945,9 @@
     
     if(ret != REQ_PROCEED) {
         // default error handler
-        nsapi_error_request((Session*)sn, (Request*)rq);
+        if(!rq->rq.senthdrs) {
+            nsapi_error_request((Session*)sn, (Request*)rq);
+        }
     }
 
     return ret;
--- a/src/server/daemon/protocol.c	Sat Jan 18 16:48:03 2020 +0100
+++ b/src/server/daemon/protocol.c	Sun Jan 19 09:01:39 2020 +0100
@@ -377,6 +377,16 @@
     return 0;
 }
 
+int http_send_continue(Session *sn) {
+    NSAPISession *s = (NSAPISession*)sn;
+    sstr_t msg = S("HTTP/1.1 100 Continue\r\n\r\n");
+    int w = s->connection->write(s->connection, msg.ptr, msg.length);
+    if(w != msg.length) {
+        return 1;
+    }
+    return 0;
+}
+
 int request_header(char *name, char **value, Session *sn, Request *rq) {
     const pb_key *key = pblock_key(name);
     pb_param *pp = pblock_findkey(key, rq->headers);
--- a/src/server/daemon/protocol.h	Sat Jan 18 16:48:03 2020 +0100
+++ b/src/server/daemon/protocol.h	Sun Jan 19 09:01:39 2020 +0100
@@ -46,6 +46,8 @@
 
 int http_start_response(Session *sn, Request *rq);
 
+int http_send_continue(Session *sn);
+
 int request_header(char *name, char **value, Session *sn, Request *rq);
 
 void http_get_scheme_host_port(
--- a/src/server/util/io.c	Sat Jan 18 16:48:03 2020 +0100
+++ b/src/server/util/io.c	Sun Jan 19 09:01:39 2020 +0100
@@ -269,8 +269,10 @@
         io[1].iov_len = nbytes;
         io[2].iov_base = "\r\n";
         io[2].iov_len = 2;
+        // TODO: FIXME: if r < sum of iov_len, everything would explode
+        // we need to store the chunk state and remaining bytes
         ssize_t r = fd->writev(fd, io, 3);
-        return r - io[0].iov_len;
+        return r - io[0].iov_len - io[2].iov_len;
     } else {
         return fd->write(fd, buf, nbytes);
     }
--- a/src/server/webdav/webdav.c	Sat Jan 18 16:48:03 2020 +0100
+++ b/src/server/webdav/webdav.c	Sun Jan 19 09:01:39 2020 +0100
@@ -45,6 +45,7 @@
 #include "../util/util.h"
 #include "../daemon/session.h"
 #include "../daemon/http.h"
+#include "../daemon/protocol.h"
 
 static UcxMap *method_handler_map;
 
@@ -162,6 +163,15 @@
 }
 
 int webdav_propfind(pblock *pb, Session *sn, Request *rq) {
+    char *expect = pblock_findkeyval(pb_key_expect, rq->headers);
+    if(expect) {
+        if(!strcasecmp(expect, "100-continue")) {
+            if(http_send_continue(sn)) {
+                return REQ_ABORTED;
+            }
+        }
+    }
+    
     UcxBuffer *reqbody = rqbody2buffer(sn, rq);
     if(!reqbody) {
         return REQ_ABORTED;

mercurial