--------------------- PatchSet 1119 Date: 2001/01/06 14:45:16 Author: adri Branch: modio Tag: (none) Log: Split up some of the client request handling to support storeLookup(). The magic goes like this: * in clientProcessRequest(), if the request isn't a seperate "protocol" we call storeLookup() to start the lookup on the object * the final bit in clientProcessRequest() which either starts a storeClientCopy() for a hit or punts to clientProcessMiss() is split into a new function - clientProcessRequestDone(). This is done because the old clientProcessRequest2() (which did the lookups) is now split into multiple blocking parts. * that will hit clientLookupDone(). If the object wasn't found, we check if its a HEAD. If so, we try a GET lookup, because we can get the relevant information from it. Otherwise, we call clientProcessRequest2() to get the log_type and then we punt to clientProcessRequestDone() (regardless of whether we found the object or not, its handled) * If we do the HEAD -> GET lookup, we will hit clientLookupHeadDone(). here we do the same thing - call clientProcessRequest2() and then clientProcessRequestDone() * When the request eventually hits clientProcessRequestDone(), its handled in the "normal" way. Members: src/client_side.c:1.2.2.11->1.2.2.12 Index: squid/src/client_side.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/client_side.c,v retrieving revision 1.2.2.11 retrieving revision 1.2.2.12 diff -u -r1.2.2.11 -r1.2.2.12 --- squid/src/client_side.c 6 Jan 2001 13:11:02 -0000 1.2.2.11 +++ squid/src/client_side.c 6 Jan 2001 14:45:16 -0000 1.2.2.12 @@ -1,6 +1,6 @@ /* - * $Id: client_side.c,v 1.2.2.11 2001/01/06 13:11:02 adri Exp $ + * $Id: client_side.c,v 1.2.2.12 2001/01/06 14:45:16 adri Exp $ * * DEBUG: section 33 Client-side Routines * AUTHOR: Duane Wessels @@ -113,12 +113,14 @@ static int clientHierarchical(clientHttpRequest * http); static int clientCheckContentLength(request_t * r); static DEFER httpAcceptDefer; -static log_type clientProcessRequest2(clientHttpRequest * http); +static log_type clientProcessRequest2(clientHttpRequest * http, StoreEntry *e); static int clientReplyBodyTooLarge(int clen); static int clientRequestBodyTooLarge(int clen); static void httpMemFree(void *, int); static STGETDONE clientPurgeRequest; - +static STGETDONE clientLookupDone; +static STGETDONE clientLookupHeadDone; +static void clientProcessRequestDone(clientHttpRequest *http); static void httpMemFree(void *data, int notused) { @@ -2027,16 +2029,54 @@ return 1; } + +/* + * clientLookupDone - handle the result of the first lookup + * + * If the result of the first lookup is a MISS and the method is METHOD_HEAD, + * we can generate a HEAD reply from a cached GET object, so initiate a + * second lookup. Otherwise, call clientProcessRequest2() to get the + * cache hit/miss information, and punt to clientProcessRequestDone(). + */ +static void +clientLookupDone(void *data, StoreEntry *e) +{ + clientHttpRequest *http = data; + + if (http->request->method == METHOD_HEAD && e == NULL) { + /* Start off the GET lookup */ + storeLookup(http->uri, METHOD_GET, clientLookupHeadDone, http); + } else { + /* We have to continue with our result, NULL or not */ + http->log_type = clientProcessRequest2(http, e); + clientProcessRequestDone(http); + } + /* NOTREACHED */ +} + +/* + * clientLookupHeadDone - handle the HEAD -> GET request + * + * Similar to clientLookupDone(), we simply call clientProcessRequest2 + */ +static void +clientLookupHeadDone(void *data, StoreEntry *e) +{ + clientHttpRequest *http = data; + + http->log_type = clientProcessRequest2(http, e); + clientProcessRequestDone(http); +} + +/* + * decide whether we've got a cache HIT or MISS, and then punt across + * to clientProcessRequestDone() + */ static log_type -clientProcessRequest2(clientHttpRequest * http) +clientProcessRequest2(clientHttpRequest * http, StoreEntry *e) { request_t *r = http->request; - StoreEntry *e; - e = http->entry = storeGetPublic(http->uri, r->method); - if (r->method == METHOD_HEAD && e == NULL) { - /* We can generate a HEAD reply from a cached GET object */ - e = http->entry = storeGetPublic(http->uri, METHOD_GET); - } + /* Release negatively cached IP-cache entries on reload */ if (r->flags.nocache) ipcacheInvalidate(r->host); @@ -2155,19 +2195,36 @@ /* XXX oof, POST can be cached! */ pumpInit(fd, r, http->uri); } else { - http->log_type = clientProcessRequest2(http); + /* We need to initiate a lookup, so defer completing the request */ + debug(33, 3) ("clientProcessRequest: looking up %s\n", http->uri); + storeLookup(http->uri, r->method, clientLookupDone, http); + return; } - debug(33, 4) ("clientProcessRequest: %s for '%s'\n", + /* Continue processing */ + clientProcessRequestDone(http); +} + + +/* + * clientProcessRequestDone - the completion of the request chain + * + * Either start getting data from a cached object, or punt across + * to clientProcessMiss(). + */ +static void +clientProcessRequestDone(clientHttpRequest *http) +{ + debug(33, 4) ("clientProcessRequestDone: %s for '%s'\n", log_tags[http->log_type], http->uri); http->out.offset = 0; if (NULL != http->entry) { storeLockObject(http->entry); storeCreateMemObject(http->entry, http->uri, http->log_uri); - http->entry->mem_obj->method = r->method; + http->entry->mem_obj->method = http->request->method; storeClientRegister(http->entry, http); #if DELAY_POOLS - delaySetStoreClient(http->sc, delayClient(r)); + delaySetStoreClient(http->sc, delayClient(http->request)); #endif http->bufofs = 0; storeClientCopy(http->entry,