Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
http_value.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010 Google Inc.
3  *
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
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
18 
19 #ifndef NET_INSTAWEB_HTTP_PUBLIC_HTTP_VALUE_H_
20 #define NET_INSTAWEB_HTTP_PUBLIC_HTTP_VALUE_H_
21 
22 #include <cstddef>
23 
29 
30 namespace net_instaweb {
31 
32 class ResponseHeaders;
33 class MessageHandler;
34 
38 class HTTPValue : public Writer {
39  public:
40  HTTPValue() : contents_size_(0) {}
41 
43  void Clear();
44 
46  bool Empty() const { return storage_.empty(); }
47 
57  void SetHeaders(ResponseHeaders* headers);
58 
63  virtual bool Write(const StringPiece& str, MessageHandler* handler);
64  virtual bool Flush(MessageHandler* handler);
65 
67  bool ExtractHeaders(ResponseHeaders* headers, MessageHandler* handler) const;
68 
72  bool ExtractContents(StringPiece* str) const;
73 
75  bool unique() const { return storage_.unique(); }
76 
82  bool Link(const SharedString& src, ResponseHeaders* headers,
83  MessageHandler* handler);
84 
87  void Link(HTTPValue* src) {
88  if (src != this) {
89  storage_ = src->storage_;
90  contents_size_ = src->contents_size();
91  }
92  }
93 
95  const SharedString& share() const { return storage_; }
96 
97  size_t size() const { return storage_.size(); }
98  int64 contents_size() { return contents_size_; }
99 
102  static bool Decode(StringPiece encoded_value, GoogleString* http_string,
103  MessageHandler* handler);
105  static bool Encode(StringPiece http_string, GoogleString* encoded_value,
106  MessageHandler* handler);
107 
108  private:
109  friend class HTTPValueTest;
110 
112  char type_identifier() const { return *storage_.data(); }
113 
114  unsigned int SizeOfFirstChunk() const;
115  void SetSizeOfFirstChunk(unsigned int size);
116  int64 ComputeContentsSize() const;
117 
120  void CopyOnWrite();
121 
122  SharedString storage_;
124  int64 contents_size_;
125 
126 
127 };
128 
129 }
130 
131 #endif
static bool Decode(StringPiece encoded_value, GoogleString *http_string, MessageHandler *handler)
Definition: http_value.h:38
static bool Encode(StringPiece http_string, GoogleString *encoded_value, MessageHandler *handler)
Convert from raw HTTP stream to HTTPValue format.
const SharedString & share() const
Access the shared string, for insertion into a cache via Put.
Definition: http_value.h:95
Read/write API for HTTP response headers.
Definition: response_headers.h:37
bool unique() const
Definition: shared_string.h:146
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
bool Empty() const
Is this HTTPValue empty.
Definition: http_value.h:46
bool ExtractContents(StringPiece *str) const
bool Link(const SharedString &src, ResponseHeaders *headers, MessageHandler *handler)
Definition: shared_string.h:40
Interface for writing bytes to an output stream.
Definition: writer.h:29
int size() const
Computes the size, taking into account any removed prefix or suffix.
Definition: shared_string.h:125
void Clear()
Clears the value (both headers and content)
bool unique() const
Tests whether this reference is the only active one to the string object.
Definition: http_value.h:75
Definition: message_handler.h:39
void SetHeaders(ResponseHeaders *headers)
void Link(HTTPValue *src)
Definition: http_value.h:87
bool ExtractHeaders(ResponseHeaders *headers, MessageHandler *handler) const
Retrieves the headers, returning false if empty.
virtual bool Write(const StringPiece &str, MessageHandler *handler)