Implement range requests with attachments; we may need to inspect the first chunk...
[citadel.git] / webcit / messages.c
index 3444d6f9f69512eec49a2411115897679a76c538..3eaef681715a05c7e64417c55562242b8e8bc088 100644 (file)
@@ -1803,6 +1803,7 @@ void postpart(StrBuf *partnum, StrBuf *filename, int force_download)
  */
 void mimepart(int force_download)
 {
+       int detect_mime = 0;
        long msgnum;
        long ErrorDetail;
        StrBuf *att;
@@ -1824,26 +1825,29 @@ void mimepart(int force_download)
                StrBufExtract_token(ContentType, Buf, 3, '|');
                CheckGZipCompressionAllowed (SKEY(ContentType));
                if (force_download)
+               {
                        FlushStrBuf(ContentType);
-
-
-               serv_read_binary(WCC->WBuf, bytes, Buf);
-               serv_puts("CLOS");
-               StrBuf_ServGetln(Buf);
-               CT = ChrPtr(ContentType);
-
-               if (!force_download) {
-                       if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
+                       detect_mime = 0;
+               }
+               else
+               {
+                       if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream"))
+                       {
                                StrBufExtract_token(Buf, WCC->Hdr->HR.ReqLine, 2, '/');
                                CT = GuessMimeByFilename(SKEY(Buf));
-                               CheckGZipCompressionAllowed (CT, strlen(CT));
+                               StrBufPlain(ContentType, CT, -1);
                        }
-                       if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream")) {
-                               CT = GuessMimeType(SKEY(WCC->WBuf));
-                               CheckGZipCompressionAllowed (CT, strlen(CT));
+                       if (!strcasecmp(ChrPtr(ContentType), "application/octet-stream"))
+                       {
+                               detect_mime = 1;
                        }
                }
-               http_transmit_thing(CT, 0);
+               serv_read_binary_to_http(ContentType, bytes, 0, detect_mime);
+
+               serv_read_binary(WCC->WBuf, bytes, Buf);
+               serv_puts("CLOS");
+               StrBuf_ServGetln(Buf);
+               CT = ChrPtr(ContentType);
        } else {
                StrBufCutLeft(Buf, 4);
                switch (ErrorDetail) {
@@ -1863,7 +1867,12 @@ void mimepart(int force_download)
                        hprintf("HTTP/1.1 500 %s\n", ChrPtr(Buf));
                        break;
                }
-               output_headers(0, 0, 0, 0, 0, 0);
+
+               hprintf("Pragma: no-cache\r\n"
+                       "Cache-Control: no-store\r\n"
+                       "Expires: -1\r\n"
+               );
+
                hprintf("Content-Type: text/plain\r\n");
                begin_burst();
                wc_printf(_("An error occurred while retrieving this part: %s\n"),