]> git.ipfire.org Git - thirdparty/squid.git/blame - src/adaptation/Message.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / adaptation / Message.cc
CommitLineData
cb255235 1/*
bde978a6 2 * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
bbc27441
AJ
3 *
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
cb255235
AR
7 */
8
bbc27441
AJ
9/* DEBUG: section 93 Adaptation */
10
582c2af2 11#include "squid.h"
cb255235 12#include "adaptation/Message.h"
3d93a84d
AJ
13#include "base/TextException.h"
14#include "HttpMsg.h"
cb255235
AR
15
16Adaptation::Message::Message(): header(NULL)
17{
18}
19
20Adaptation::Message::Message(Header *aHeader): header(NULL)
21{
22 set(aHeader);
23}
24
25Adaptation::Message::~Message()
26{
27 clear();
28}
29
30void
31Adaptation::Message::clear()
32{
33 HTTPMSGUNLOCK(header);
34 body_pipe = NULL;
35}
36
37void
38Adaptation::Message::set(Header *aHeader)
39{
40 clear();
41 if (aHeader) {
b248c2a3
AJ
42 header = aHeader;
43 HTTPMSGLOCK(header);
cb255235
AR
44 body_pipe = header->body_pipe;
45 }
46}
47
48void
d1649fba 49Adaptation::Message::ShortCircuit(Message &src, Message &dest)
cb255235 50{
d1649fba
AR
51 Must(!dest.header); // the message is not "used"
52 Must(!dest.body_pipe); // can relax if needed, but need !body_pipe->used()
53 Must(src.header); // or there is nothing to shortcircuit
54
55 if (src.header->body_pipe != NULL) {
56 // check that it would not be too late to shortcircuit the pipe
57 Must(!src.header->body_pipe->consumedSize());
58 src.header->body_pipe->clearConsumer(); // if any
59 // note: current header->body_pipe producer may later become
60 // dest.body_pipe consumer and consume its own data
61 // TODO: consumer should detect and bypass short-circuit adaptation
cb255235 62 }
d1649fba 63 dest.set(src.header->clone());
cb255235 64}
f53969cc 65