check if service SAFs sent a response, terminate connection in case no response was sent webdav

Sat, 14 May 2022 15:22:37 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sat, 14 May 2022 15:22:37 +0200
branch
webdav
changeset 360
79ddd772e807
parent 359
79b28ae7bfbd
child 361
570026d3a685

check if service SAFs sent a response, terminate connection in case no response was sent

src/server/daemon/httprequest.c file | annotate | diff | comparison | revisions
--- a/src/server/daemon/httprequest.c	Sat May 14 15:21:59 2022 +0200
+++ b/src/server/daemon/httprequest.c	Sat May 14 15:22:37 2022 +0200
@@ -579,6 +579,14 @@
         // TODO: reuse buffer in next request
         rq->rq.rq_attr.keep_alive = 0; // workaround
     }
+    if(!rq->rq.senthdrs) {
+        // why was no response sent?
+        // something must have gone wrong
+        // terminate the session
+        char *clf_req = pblock_findkeyval(pb_key_clf_request, rq->rq.reqpb);
+        log_ereport(LOG_WARN, "nsapi_finish_request: no response header: request: %s", clf_req);
+        rq->rq.rq_attr.keep_alive = 0;
+    }
     
     if(rq->rq.rq_attr.keep_alive) {
         SessionHandler *sh = sn->connection->session_handler;
@@ -891,9 +899,17 @@
             
             if(ret != REQ_NOACTION) {
                 if(ret == REQ_PROCEED) {
-                    // flush buffer and add termination if chunked encoding
-                    // is enabled
-                    net_finish(sn->sn.csd);
+                    if(rq->rq.senthdrs) {
+                        // flush buffer and add termination if chunked encoding
+                        // is enabled
+                        net_finish(sn->sn.csd);
+                    } else {
+                        // a service SAF must send a response
+                        // senthdrs == 0 indicators something has gone
+                        // wrong
+                        protocol_status(&sn->sn, &rq->rq, 500, NULL);
+                        ret = REQ_ABORTED;
+                    }
                 } else if(ret == REQ_PROCESSING) {
                     // save nsapi context
                     rq->context.objset_index = i;

mercurial