Revision: 14404
Author: adrian.chadd
Date: Sat Feb 13 23:01:13 2010
Log: Migrate the body of the ETag processing hackery out of client_side.c.


http://code.google.com/p/lusca-cache/source/detail?r=14404

Added:
 /branches/LUSCA_HEAD/src/client_side_etag.c
 /branches/LUSCA_HEAD/src/client_side_etag.h
Modified:
 /branches/LUSCA_HEAD/src/Makefile.am
 /branches/LUSCA_HEAD/src/client_side.c
 /branches/LUSCA_HEAD/src/client_side.h

=======================================
--- /dev/null
+++ /branches/LUSCA_HEAD/src/client_side_etag.c Sat Feb 13 23:01:13 2010
@@ -0,0 +1,99 @@
+#include "squid.h"
+
+#include "client_side_etag.h"
+
+static void
+clientHandleETagMiss(clientHttpRequest * http)
+{
+    StoreEntry *entry = http->entry;
+    request_t *request = http->request;
+
+    request->done_etag = 1;
+    if (request->vary) {
+       storeLocateVaryDone(request->vary);
+       request->vary = NULL;
+       request->etags = NULL;       /* pointed into request->vary */
+    }
+    safe_free(request->etag);
+    safe_free(request->vary_headers);
+    safe_free(request->vary_hdr);
+    storeClientUnregister(http->sc, entry, http);
+    storeUnlockObject(entry);
+    http->entry = NULL;
+    clientProcessRequest(http);
+}
+
+static void
+clientHandleETagReply(void *data, HttpReply * rep)
+{
+    //const char *buf = ref.node->data + ref.offset;
+    clientHttpRequest *http = data;
+    StoreEntry *entry = http->entry;
+    const char *url = storeLookupUrl(entry);
+    if (entry == NULL) {
+       /* client aborted */
+       return;
+    }
+    if (!rep) {
+       debug(33, 3) ("clientHandleETagReply: FAILED '%s'\n", url);
+       clientHandleETagMiss(http);
+       return;
+    }
+    if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) {
+       debug(33, 3) ("clientHandleETagReply: ABORTED '%s'\n", url);
+       clientHandleETagMiss(http);
+       return;
+    }
+ debug(33, 3) ("clientHandleETagReply: %s = %d\n", url, (int) rep->sline.status);
+    if (HTTP_NOT_MODIFIED == rep->sline.status) {
+       /* Remember the ETag and restart */
+       if (rep) {
+           request_t *request = http->request;
+           const char *etag = httpHeaderGetStr(&rep->header, HDR_ETAG);
+           const char *vary = request->vary_headers;
+           int has_vary = httpHeaderHas(&rep->header, HDR_VARY);
+#if X_ACCELERATOR_VARY
+           has_vary |= httpHeaderHas(&rep->header, HDR_X_ACCELERATOR_VARY);
+#endif
+           if (has_vary)
+               vary = httpMakeVaryMark(request, rep);
+
+           if (etag && vary) {
+               char *str;
+               str = stringDupToC(&request->vary_encoding);
+ storeAddVary(url, entry->mem_obj->method, NULL, httpHeaderGetStr(&rep->header, HDR_ETAG), request->vary_hdr, request->vary_headers, str);
+               safe_free(str);
+           }
+       }
+       clientHandleETagMiss(http);
+       return;
+    }
+    /* Send the new object to the client */
+    clientSendHeaders(data, rep);
+    return;
+}
+
+void
+clientProcessETag(clientHttpRequest * http)
+{
+    char *url = http->uri;
+    StoreEntry *entry = NULL;
+    debug(33, 3) ("clientProcessETag: '%s'\n", http->uri);
+ entry = storeCreateEntry(url, http->request->flags, http->request->method);
+    if (http->request->store_url)
+       storeEntrySetStoreUrl(entry, http->request->store_url);
+    http->sc = storeClientRegister(entry, http);
+#if DELAY_POOLS
+    /* delay_id is already set on original store client */
+    delaySetStoreClient(http->sc, delayClient(http));
+#endif
+    http->entry = entry;
+    http->out.offset = 0;
+    fwdStart(http->conn->fd, http->entry, http->request);
+ /* Register with storage manager to receive updates when data comes in. */
+    if (EBIT_TEST(entry->flags, ENTRY_ABORTED))
+       debug(33, 0) ("clientProcessETag: found ENTRY_ABORTED object\n");
+    storeClientCopyHeaders(http->sc, entry,
+       clientHandleETagReply,
+       http);
+}
=======================================
--- /dev/null
+++ /branches/LUSCA_HEAD/src/client_side_etag.h Sat Feb 13 23:01:13 2010
@@ -0,0 +1,6 @@
+#ifndef        __CLIENT_SIDE_ETAG_H__
+#define        __CLIENT_SIDE_ETAG_H__
+
+extern void clientProcessETag(clientHttpRequest * http);
+
+#endif
=======================================
--- /branches/LUSCA_HEAD/src/Makefile.am        Thu Feb 11 23:26:11 2010
+++ /branches/LUSCA_HEAD/src/Makefile.am        Sat Feb 13 23:01:13 2010
@@ -108,6 +108,7 @@
        client_db.c \
        client_side.c \
        client_side_body.c \
+       client_side_etag.c \
        client_side_request.c \
        client_side_reply.c \
        client_side_conn.c \
=======================================
--- /branches/LUSCA_HEAD/src/client_side.c      Sat Feb 13 22:52:19 2010
+++ /branches/LUSCA_HEAD/src/client_side.c      Sat Feb 13 23:01:13 2010
@@ -40,6 +40,7 @@
 #include "client_side_request.h"
 #include "client_side_ranges.h"
 #include "client_side_async_refresh.h"
+#include "client_side_etag.h"

 #include "client_side.h"

@@ -74,7 +75,6 @@

 static int clientOnlyIfCached(clientHttpRequest * http);
 static STNCB clientSendMoreData;
-static STHCB clientSendHeaders;
 static STHCB clientCacheHit;
 static void clientSetKeepaliveFlag(clientHttpRequest *);
 static int clientCachable(clientHttpRequest * http);
@@ -156,102 +156,6 @@
     storeClientCopyHeaders(h->sc, e, clientSendHeaders, h);
     return e;
 }
-
-static void
-clientHandleETagMiss(clientHttpRequest * http)
-{
-    StoreEntry *entry = http->entry;
-    request_t *request = http->request;
-
-    request->done_etag = 1;
-    if (request->vary) {
-       storeLocateVaryDone(request->vary);
-       request->vary = NULL;
-       request->etags = NULL;       /* pointed into request->vary */
-    }
-    safe_free(request->etag);
-    safe_free(request->vary_headers);
-    safe_free(request->vary_hdr);
-    storeClientUnregister(http->sc, entry, http);
-    storeUnlockObject(entry);
-    http->entry = NULL;
-    clientProcessRequest(http);
-}
-
-static void
-clientHandleETagReply(void *data, HttpReply * rep)
-{
-    //const char *buf = ref.node->data + ref.offset;
-    clientHttpRequest *http = data;
-    StoreEntry *entry = http->entry;
-    const char *url = storeLookupUrl(entry);
-    if (entry == NULL) {
-       /* client aborted */
-       return;
-    }
-    if (!rep) {
-       debug(33, 3) ("clientHandleETagReply: FAILED '%s'\n", url);
-       clientHandleETagMiss(http);
-       return;
-    }
-    if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) {
-       debug(33, 3) ("clientHandleETagReply: ABORTED '%s'\n", url);
-       clientHandleETagMiss(http);
-       return;
-    }
- debug(33, 3) ("clientHandleETagReply: %s = %d\n", url, (int) rep->sline.status);
-    if (HTTP_NOT_MODIFIED == rep->sline.status) {
-       /* Remember the ETag and restart */
-       if (rep) {
-           request_t *request = http->request;
-           const char *etag = httpHeaderGetStr(&rep->header, HDR_ETAG);
-           const char *vary = request->vary_headers;
-           int has_vary = httpHeaderHas(&rep->header, HDR_VARY);
-#if X_ACCELERATOR_VARY
-           has_vary |= httpHeaderHas(&rep->header, HDR_X_ACCELERATOR_VARY);
-#endif
-           if (has_vary)
-               vary = httpMakeVaryMark(request, rep);
-
-           if (etag && vary) {
-               char *str;
-               str = stringDupToC(&request->vary_encoding);
- storeAddVary(url, entry->mem_obj->method, NULL, httpHeaderGetStr(&rep->header, HDR_ETAG), request->vary_hdr, request->vary_headers, str);
-               safe_free(str);
-           }
-       }
-       clientHandleETagMiss(http);
-       return;
-    }
-    /* Send the new object to the client */
-    clientSendHeaders(data, rep);
-    return;
-}
-
-static void
-clientProcessETag(clientHttpRequest * http)
-{
-    char *url = http->uri;
-    StoreEntry *entry = NULL;
-    debug(33, 3) ("clientProcessETag: '%s'\n", http->uri);
- entry = storeCreateEntry(url, http->request->flags, http->request->method);
-    if (http->request->store_url)
-       storeEntrySetStoreUrl(entry, http->request->store_url);
-    http->sc = storeClientRegister(entry, http);
-#if DELAY_POOLS
-    /* delay_id is already set on original store client */
-    delaySetStoreClient(http->sc, delayClient(http));
-#endif
-    http->entry = entry;
-    http->out.offset = 0;
-    fwdStart(http->conn->fd, http->entry, http->request);
- /* Register with storage manager to receive updates when data comes in. */
-    if (EBIT_TEST(entry->flags, ENTRY_ABORTED))
-       debug(33, 0) ("clientProcessETag: found ENTRY_ABORTED object\n");
-    storeClientCopyHeaders(http->sc, entry,
-       clientHandleETagReply,
-       http);
-}

 void
 clientProcessExpired(clientHttpRequest * http)
@@ -1918,7 +1822,7 @@
* accepts chunk of a http message in buf, parses prefix, filters headers and
  * such, writes processed message to the client's socket
  */
-static void
+void
 clientSendHeaders(void *data, HttpReply * rep)
 {
     //const char *buf = ref.node->data + ref.offset;
=======================================
--- /branches/LUSCA_HEAD/src/client_side.h      Thu Feb 11 23:26:11 2010
+++ /branches/LUSCA_HEAD/src/client_side.h      Sat Feb 13 23:01:13 2010
@@ -15,5 +15,6 @@
 extern void clientProcessOnlyIfCachedMiss(clientHttpRequest * http);
 extern void httpRequestFree(void *data);
 extern void clientKeepaliveNextRequest(clientHttpRequest * http);
+extern STHCB clientSendHeaders;

 #endif

--
You received this message because you are subscribed to the Google Groups 
"lusca-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/lusca-commit?hl=en.

Reply via email to