src/server/daemon/http.c

changeset 385
a1f4cb076d2f
parent 345
5832e10fc59a
--- a/src/server/daemon/http.c	Tue Aug 13 22:14:32 2019 +0200
+++ b/src/server/daemon/http.c	Sat Sep 24 16:26:10 2022 +0200
@@ -198,7 +198,7 @@
 
 /* ---------------------------- http_set_finfo ---------------------------- */
 
-static inline int set_finfo(Session *sn, Request *rq, off_t size, time_t mtime)
+static inline int set_finfo(Session *sn, Request *rq, off_t size, time_t mtime, const char *etag)
 {
     struct tm mtms;
     struct tm *mtm = system_gmtime(&mtime, &mtms);
@@ -223,15 +223,19 @@
     snprintf(pp->value, content_length_size, "%lld", (long long)size);
     pblock_kpinsert(pb_key_content_length, pp, rq->srvhdrs);
 
-    char *etag;
     if (http_etag) {
         /* Insert Etag */
-        pp = pblock_key_param_create(rq->srvhdrs, pb_key_etag, NULL, MAX_ETAG);
-        if (!pp || !pp->value)
-            return REQ_ABORTED;
-        http_format_etag(sn, rq, pp->value, MAX_ETAG, size, mtime);
-        pblock_kpinsert(pb_key_etag, pp, rq->srvhdrs);
-        etag = pp->value;
+        if(etag) {
+            pblock_kvinsert(pb_key_etag, etag, strlen(etag), rq->srvhdrs);
+        } else {
+            pp = pblock_key_param_create(rq->srvhdrs, pb_key_etag, NULL, MAX_ETAG);
+            if (!pp || !pp->value)
+                return REQ_ABORTED;
+            http_format_etag(sn, rq, pp->value, MAX_ETAG, size, mtime);
+            pblock_kpinsert(pb_key_etag, pp, rq->srvhdrs);
+            etag = pp->value;
+        }
+        
     } else {
         etag = NULL;
     }
@@ -242,7 +246,11 @@
 
 NSAPI_PUBLIC int http_set_finfo(Session *sn, Request *rq, struct stat *finfo)
 {
-    return set_finfo(sn, rq, finfo->st_size, finfo->st_mtime);
+    return set_finfo(sn, rq, finfo->st_size, finfo->st_mtime, NULL);
+}
+
+NSAPI_PUBLIC int http_set_finfo_etag(Session *sn, Request *rq, struct stat *finfo, const char *etag) {
+    return set_finfo(sn, rq, finfo->st_size, finfo->st_mtime, etag);
 }
 
 

mercurial