Browse Source

http: a bit more cache mangling...

H. Peter Anvin 2 years ago
parent
commit
aae0790411
4 changed files with 17 additions and 14 deletions
  1. 17 14
      esp32/max80/httpd.c
  2. BIN
      esp32/output/max80.ino.bin
  3. BIN
      fpga/output/v1.fw
  4. BIN
      fpga/output/v2.fw

+ 17 - 14
esp32/max80/httpd.c

@@ -141,13 +141,6 @@ static const char *http_dos_date(uint32_t dos_date)
 
 static const char text_plain[] = "text/plain; charset=\"UTF-8\"";
 
-enum hsp_flags {
-    HSP_CLOSE        = 1,
-    HSP_CRLF         = 2,
-    HSP_CLOSE_SOCKET = 4,
-    HSP_REFERER      = 8	/* Use referer as body (for redirects) */
-};
-
 static void httpd_print_request(const httpd_req_t *req)
 {
     printf("[HTTP] %s %s\n", http_method_str(req->method), req->uri);
@@ -169,6 +162,13 @@ static char *httpd_req_get_hdr(httpd_req_t *req, const char *field, size_t *lenp
     return val;
 }
 
+enum hsp_flags {
+    HSP_CRLF         = 1,    /* Append CR LF to the body */
+    HSP_CLOSE        = 2,    /* Add a Connection: close header */
+    HSP_REFERER      = 4,    /* Use referer as body (for redirects) */
+    HSP_UNCACHE      = 8     /* Wipe caches, please... */
+};
+
 static esp_err_t httpd_send_plain(httpd_req_t *req,
 				  unsigned int rcode,
 				  const char *body, size_t blen,
@@ -208,6 +208,8 @@ static esp_err_t httpd_send_plain(httpd_req_t *req,
     }
 
     const char * const refresher = refresher_buf ? refresher_buf : "";
+    const char * const uncacher = (flags & HSP_UNCACHE)
+      ? "Clear-Site-Data: \"cache\",\"executionContexts\"\r\n" : "";
 
     if (redirect) {
 	/* \0 -> \n so don't include it */
@@ -230,11 +232,13 @@ static esp_err_t httpd_send_plain(httpd_req_t *req,
 			"Content-Length: %zu\r\n"
 			"Date %s\r\n"
 			"Location: %.*s\r\n"
-			"%s%s"
+			"%s%s%s"
 			"\r\n"
 			"%3u Redirect ",
 			rcode, text_plain, blen + blenadj,
-			now, (int)blen, body, closer, refresher, rcode);
+			now, (int)blen, body,
+			closer, refresher, uncacher,
+			rcode);
     } else {
 	size_t blenadj = (flags & HSP_CRLF) ? 2 : 0;
 
@@ -244,10 +248,10 @@ static esp_err_t httpd_send_plain(httpd_req_t *req,
 			"Content-Length: %zu\r\n"
 			"Cache-Control: no-cache\r\n"
 			"Date: %s\r\n"
-			"%s%s"
+			"%s%s%s"
 			"\r\n",
 			rcode, text_plain, blen + blenadj, now,
-			closer, refresher);
+			closer, refresher, uncacher);
     }
 
     if (refresher_buf)
@@ -270,8 +274,7 @@ static esp_err_t httpd_send_plain(httpd_req_t *req,
     if (header)
 	free(header);
 
-    /* Sending ESP_FAIL causes the socket to be immediately closed */
-    return err ? err : (flags & HSP_CLOSE_SOCKET) ? ESP_FAIL : ESP_OK;
+    return err;
 }
 
 #define SL(s) (s), (sizeof(s)-1)
@@ -314,7 +317,7 @@ static esp_err_t httpd_update_done(httpd_req_t *req, const char *what, int err)
 	len = 0;
 
     esp_err_t rv = httpd_send_plain(req, err ? 400 : 200, response, len,
-				    HSP_CLOSE, reboot_time+5);
+				    HSP_CLOSE|HSP_UNCACHE, reboot_time+5);
     if (response)
 	free(response);
 

BIN
esp32/output/max80.ino.bin


BIN
fpga/output/v1.fw


BIN
fpga/output/v2.fw