--------------------- PatchSet 2410 Date: 2001/05/30 21:27:02 Author: hno Branch: etag Tag: (none) Log: Rough cut at a request path for ETag queries. Members: src/client_side.c:1.29.2.3->1.29.2.4 Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.29.2.3 retrieving revision 1.29.2.4 diff -u -r1.29.2.3 -r1.29.2.4 --- squid/src/client_side.c 30 May 2001 10:08:45 -0000 1.29.2.3 +++ squid/src/client_side.c 30 May 2001 21:27:02 -0000 1.29.2.4 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.29.2.3 2001/05/30 10:08:45 hno Exp $ + * $Id: client_side.c,v 1.29.2.4 2001/05/30 21:27:02 hno Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -351,6 +351,93 @@ } static void +clientHandleETagMiss(clientHttpRequest *http) +{ + StoreEntry *entry = http->entry; + storeUnregister(http->sc, entry, http); + storeUnlockObject(entry); + clientProcessRequest(http); +} + +static void +clientHandleETagReply(void *data, char *buf, ssize_t size) +{ + clientHttpRequest *http = data; + StoreEntry *entry = http->entry; + MemObject *mem; + const char *url = storeUrl(entry); + http_status status; + debug(33, 3) ("clientHandleETagReply: %s, %d bytes\n", url, (int) size); + if (entry == NULL) { + memFree(buf, MEM_CLIENT_SOCK_BUF); + clientHandleETagMiss(http); + } + if (size < 0 && !EBIT_TEST(entry->flags, ENTRY_ABORTED)) { + memFree(buf, MEM_CLIENT_SOCK_BUF); + clientHandleETagMiss(http); + } + mem = entry->mem_obj; + status = mem->reply->sline.status; + if (EBIT_TEST(entry->flags, ENTRY_ABORTED)) { + debug(33, 3) ("clientHandleETagReply: ABORTED '%s'\n", url); + clientHandleETagMiss(http); + return; + } else if (STORE_PENDING == entry->store_status && 0 == status) { + debug(33, 3) ("clientHandleETagReply: Incomplete headers for '%s'\n", url); + if (size >= CLIENT_SOCK_SZ) { + /* will not get any bigger than that */ + debug(33, 3) ("clientHandleETagReply: Reply is too large '%s'\n", url); + clientHandleETagMiss(http); + return; + } else { + storeClientCopy(http->sc, entry, + http->out.offset + size, + http->out.offset, + CLIENT_SOCK_SZ, + buf, + clientHandleETagReply, + http); + return; + } + } else { + /* XXX Much more to do here. This only covers the + * case where the client SHOULD receive the object + */ + clientSendMoreData(data, buf, size); + } +} + +static void +clientProcessETag(clientHttpRequest *http) +{ + char *url = http->uri; + StoreEntry *entry = NULL; + debug(33, 3) ("clientProcessETag: '%s'\n", http->uri); + entry = storeCreateEntry(url, + http->log_uri, + http->request->flags, + http->request->method); + http->sc = storeClientListAdd(entry, http); +#if DELAY_POOLS + /* delay_id is already set on original store client */ + delaySetStoreClient(http->sc, delayClient(http->request)); +#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"); + storeClientCopy(http->sc, entry, + http->out.offset, + http->out.offset, + CLIENT_SOCK_SZ, + memAllocate(MEM_CLIENT_SOCK_BUF), + clientHandleETagReply, + http); +} + +static void clientProcessExpired(void *data) { clientHttpRequest *http = data; @@ -2232,6 +2319,14 @@ if (NULL == e) { /* this object isn't in the cache */ debug(33, 3) ("clientProcessRequest2: storeGet() MISS\n"); + if (r->vary) { + if (r->etags) { + debug(33, 0) ("clientProcessRequest2: ETag miss\n"); + r->etags = NULL; + } else if (r->vary->etags.count > 0) { + r->etags = &r->vary->etags; + } + } return LOG_TCP_MISS; } if (Config.onoff.offline) { @@ -2403,9 +2498,9 @@ return; } assert(http->out.offset == 0); - http->entry = clientCreateStoreEntry(http, r->method, r->flags); if (http->redirect.status) { HttpReply *rep = httpReplyCreate(); + http->entry = clientCreateStoreEntry(http, r->method, r->flags); #if LOG_TCP_REDIRECTS http->log_type = LOG_TCP_REDIRECT; #endif @@ -2416,6 +2511,11 @@ storeComplete(http->entry); return; } + if (r->etags) { + clientProcessETag(http); + return; + } + http->entry = clientCreateStoreEntry(http, r->method, r->flags); if (http->flags.internal) r->protocol = PROTO_INTERNAL; fwdStart(http->conn->fd, http->entry, r);