On 04/25/2014 03:19 AM, Peter Belau wrote: > Also, just for my own understanding, what's fundamentally wrong with > modifying the StoreEntry?
Fundamentally, StoreEntry and StoreEntry's HttpReply is a temporary reflection of the response that was received from the server (and possibly adapted and/or cached). If your intent is to modify the cached information, affecting all from-cache responses, it should be done pre-cache (http.cc and friends). If your intent is to adjust a single to-client response, it should be done post-cache without StoreEntry modifications (clientReplyContext::buildReplyHeader and friends). Needless to say, there are exceptions and violations of the fundamental principles sketched above. HTH, Alex. > On Thursday, April 24, 2014 7:20 AM, Alex Rousskov wrote: > On 04/24/2014 04:33 AM, Peter Belau wrote: > > >> I'm trying to modify the Set-Cookie header from within >> client_side_reply.cc. Currently my code looks like this: > >> HttpReply *rep = http->storeEntry()->getReply()->clone(); >> http->storeEntry()->releaseRequest(); >> rep->header.putStr(HDR_SET_COOKIE, "FOO=bar"); >> http->storeEntry()->replaceHttpReply(rep); >> http->storeEntry()->complete(); > >> This seems to corrupt storeEntry in ways that I don't understand. I >> imagine that I'm missing something fundamental here. If someone could >> point me in the right direct, I would much appreciate it. > > > Hi Peter, > > There are at least two fundamental problems here: > > * As Eliezer has already noted, you should be using one of the many > available adaptation interfaces instead of modifying sources directly. > If the available interfaces do not do what you want, they usually can be > enhanced (or new interfaces can be added). As you said, we all have > specific reasons for doing the wrong thing, of course. > > * If you want to adjust each response, including HIT responses, you > should be modifying the response as it goes out, not the Store entry > itself. See clientReplyContext::buildReplyHeader(). If you want to > adjust the response before it may be cached (so that a cached response > is adjusted just once and served many times), then you should be doing > that in http.cc instead. > > > HTH, > > Alex. >