Page Speed Optimization Libraries  1.9.32.2
 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 #include "pagespeed/kernel/base/basictypes.h"
24 #include "pagespeed/kernel/base/shared_string.h"
25 #include "pagespeed/kernel/base/string_util.h"
26 #include "pagespeed/kernel/base/writer.h"
27 
28 namespace net_instaweb {
29 
30 class ResponseHeaders;
31 class MessageHandler;
32 
36 class HTTPValue : public Writer {
37  public:
38  HTTPValue() : contents_size_(0) {}
39 
41  void Clear();
42 
44  bool Empty() const { return storage_.empty(); }
45 
55  void SetHeaders(ResponseHeaders* headers);
56 
61  virtual bool Write(const StringPiece& str, MessageHandler* handler);
62  virtual bool Flush(MessageHandler* handler);
63 
65  bool ExtractHeaders(ResponseHeaders* headers, MessageHandler* handler) const;
66 
70  bool ExtractContents(StringPiece* str) const;
71 
73  bool unique() const { return storage_.unique(); }
74 
80  bool Link(SharedString* src, ResponseHeaders* headers,
81  MessageHandler* handler);
82 
85  void Link(HTTPValue* src) {
86  if (src != this) {
87  storage_ = src->storage_;
88  contents_size_ = src->contents_size();
89  }
90  }
91 
93  SharedString* share() { return &storage_; }
94 
95  size_t size() const { return storage_.size(); }
96  int64 contents_size() { return contents_size_; }
97 
98  private:
99  friend class HTTPValueTest;
100 
102  char type_identifier() const { return *storage_.data(); }
103 
104  unsigned int SizeOfFirstChunk() const;
105  void SetSizeOfFirstChunk(unsigned int size);
106  int64 ComputeContentsSize() const;
107 
110  void CopyOnWrite();
111 
112  SharedString storage_;
114  int64 contents_size_;
115 
116  DISALLOW_COPY_AND_ASSIGN(HTTPValue);
117 };
118 
119 }
120 
121 #endif
Definition: http_value.h:36
bool Link(SharedString *src, ResponseHeaders *headers, MessageHandler *handler)
bool Empty() const
Is this HTTPValue empty.
Definition: http_value.h:44
SharedString * share()
Access the shared string, for insertion into a cache via Put.
Definition: http_value.h:93
bool ExtractContents(StringPiece *str) const
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:73
void SetHeaders(ResponseHeaders *headers)
void Link(HTTPValue *src)
Definition: http_value.h:85
bool ExtractHeaders(ResponseHeaders *headers, MessageHandler *handler) const
Retrieves the headers, returning false if empty.
virtual bool Write(const StringPiece &str, MessageHandler *handler)