Lagrange [work/v1.15]

GmRequest: Handling early termination

=> 66b1193cfd3070bc1746ddce691e1784f0f04395

diff --git a/src/gmrequest.c b/src/gmrequest.c
index f4d770ab..0208dc94 100644
--- a/src/gmrequest.c
+++ b/src/gmrequest.c
@@ -227,7 +227,12 @@ static int processIncomingData_GmRequest_(iGmRequest *d, const iBlock *data) {
 static void readIncoming_GmRequest_(iGmRequest *d, iTlsRequest *req) {
     lock_Mutex(d->mtx);
     iGmResponse *resp = d->resp;
-    iAssert(d->state != finished_GmRequestState); /* notifications out of order? */
+    if (d->state == finished_GmRequestState || d->state == failure_GmRequestState) {
+        /* The request has already finished or been aborted (e.g., invalid header). */
+        delete_Block(readAll_TlsRequest(req));
+        unlock_Mutex(d->mtx);
+        return;
+    }
     iBlock *  data         = readAll_TlsRequest(req);
     const int ubits        = processIncomingData_GmRequest_(d, data);
     iBool     notifyUpdate = (ubits & 1) != 0;
@@ -552,7 +557,7 @@ void submit_GmRequest(iGmRequest *d) {
             remove_Block(&path->chars, 0, 1);
         }
 #endif
-        iFile *  f    = new_File(path);
+        iFile *f = new_File(path);
         if (open_File(f, readOnly_FileMode)) {
             /* TODO: Check supported file types: images, audio */
             /* TODO: Detect text files based on contents? E.g., is the content valid UTF-8. */
Proxy Information
Original URL
gemini://git.skyjake.fi/lagrange/work%2Fv1.15/cdiff/66b1193cfd3070bc1746ddce691e1784f0f04395
Status Code
Success (20)
Meta
text/gemini; charset=utf-8
Capsule Response Time
47.988999 milliseconds
Gemini-to-HTML Time
0.34866 milliseconds

This content has been proxied by September (ba2dc).