# HG changeset patch # User Olaf Wintermann # Date 1579420899 -3600 # Node ID 4990147c58d0493a5351a49401f5e2f3c7df923b # Parent f30740c3aafb64f5c6cbdcac4e430c0035dccd2a add handler for http expect header diff -r f30740c3aafb -r 4990147c58d0 src/server/daemon/httprequest.c --- 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; diff -r f30740c3aafb -r 4990147c58d0 src/server/daemon/protocol.c --- 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); diff -r f30740c3aafb -r 4990147c58d0 src/server/daemon/protocol.h --- 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( diff -r f30740c3aafb -r 4990147c58d0 src/server/util/io.c --- 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); } diff -r f30740c3aafb -r 4990147c58d0 src/server/webdav/webdav.c --- 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;