2
* Copyright 2012 Google Inc.
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
16
// Author: mmohabey@google.com (Megha Mohabey)
18
#ifndef NET_INSTAWEB_HTTP_PUBLIC_HTTP_VALUE_WRITER_H_
19
#define NET_INSTAWEB_HTTP_PUBLIC_HTTP_VALUE_WRITER_H_
21
#include "net/instaweb/util/public/basictypes.h"
22
#include "net/instaweb/util/public/string_util.h"
24
namespace net_instaweb {
29
class ResponseHeaders;
31
// Wrappper for buffering an HTTPValue. HTTPValueWriter ensures that an
32
// HTTPValue which cannot be eventually cached is not buffered.
33
class HTTPValueWriter {
35
HTTPValueWriter(HTTPValue* value, HTTPCache* cache)
38
has_buffered_(true) {}
40
void SetHeaders(ResponseHeaders* headers);
42
bool Write(const StringPiece& str, MessageHandler* handler);
44
bool has_buffered() const { return has_buffered_; }
46
// Checks if the http_value should be buffered or not depending on whether we
47
// can eventually cache it. It also clears the http_value if it can not be
48
// buffered. Note that this only checks the size constraints, not cache
50
bool CheckCanCacheElseClear(ResponseHeaders* headers);
52
// Checks if we can write the string to the HttpValue without going over
54
bool CanCacheContent(const StringPiece& str) const;
60
DISALLOW_COPY_AND_ASSIGN(HTTPValueWriter);
63
} // namespace net_instaweb
64
#endif // NET_INSTAWEB_HTTP_PUBLIC_HTTP_VALUE_WRITER_H_