Explorar o código

Cache control (Step 5/?)

bel %!s(int64=9) %!d(string=hai) anos
pai
achega
3e6cb07c00
Modificáronse 1 ficheiros con 14 adicións e 13 borrados
  1. 14 13
      src/civetweb.c

+ 14 - 13
src/civetweb.c

@@ -2093,24 +2093,25 @@ send_no_cache_header(struct mg_connection *conn)
 	 * there must be several response headers to ensure no browser caches the
 	 * response.
 	 */
-	int ret;
-	ret = mg_printf(conn,
-	                "Cache-Control: no-cache, no-store, "
-                    "must-revalidate, private, max-age=0\r\n"
-	                "Pragma: no-cache\r\n"
-	                "Expires: 0\r\n");
-	return ret;
+	return mg_printf(conn,
+	                 "Cache-Control: no-cache, no-store, "
+	                 "must-revalidate, private, max-age=0\r\n"
+	                 "Pragma: no-cache\r\n"
+	                 "Expires: 0\r\n");
 }
 
 
 static int
 send_static_cache_header(struct mg_connection *conn)
 {
-	int ret;
-	ret = mg_printf(conn,
-	                "Cache-Control: max-age=%u\r\n", 
-                    /* TODO: set some time */ 60);
-	return ret;
+	/* TODO: Get max age (in seconds) for static files from conn->ctx */
+	int max_age = 60 /* + conn->ctx.TODO */;
+
+	if (max_age <= 0) {
+		return send_no_cache_header(conn);
+	}
+
+	return mg_printf(conn, "Cache-Control: max-age=%u\r\n", max_age);
 }
 
 
@@ -9598,7 +9599,7 @@ handle_request(struct mg_connection *conn)
 			          "HTTP/1.1 301 Moved Permanently\r\n"
 			          "Location: %s/\r\n"
 			          "Date: %s\r\n"
-			          /* TODO: "Cache-Control" (private = default) */
+			          /* "Cache-Control: private\r\n" (= default) */
 			          "Content-Length: 0\r\n"
 			          "Connection: %s\r\n\r\n",
 			          ri->request_uri,