Page Speed Optimization Libraries  1.4.26.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes
net_instaweb::Headers< Proto > Class Template Reference

Read/write API for HTTP headers (shared base class) More...

#include "headers.h"

List of all members.

Public Member Functions

virtual void Clear ()
int major_version () const
bool has_major_version () const
int minor_version () const
void set_major_version (int major_version)
void set_minor_version (int major_version)
int NumAttributes () const
 Raw access for random access to attribute name/value pairs.
const GoogleStringName (int i) const
const GoogleStringValue (int i) const
bool Lookup (const StringPiece &name, ConstStringStarVector *values) const
const char * Lookup1 (const StringPiece &name) const
bool Has (const StringPiece &name) const
 Does there exist a header with given name.
bool HasValue (const StringPiece &name, const StringPiece &value) const
 Is value one of the values in Lookup(name)?
int NumAttributeNames () const
 NumAttributeNames is also const but not thread-safe.
void RemoveCookie (const StringPiece &cookie_name)
virtual void Add (const StringPiece &name, const StringPiece &value)
 Adds a new header, even if a header with the 'name' exists already.
virtual bool Remove (const StringPiece &name, const StringPiece &value)
virtual bool RemoveAll (const StringPiece &name)
 Removes all headers by name. Return true if anything was removed.
virtual bool RemoveAllFromSet (const StringSetInsensitive &names)
virtual void RemoveAllWithPrefix (const StringPiece &prefix)
 Removes all headers whose name starts with prefix.
virtual void Replace (const StringPiece &name, const StringPiece &value)
virtual void UpdateFrom (const Headers< Proto > &other)
virtual bool WriteAsBinary (Writer *writer, MessageHandler *message_handler)
 Serialize HTTP header to a binary stream.
virtual bool ReadFromBinary (const StringPiece &buf, MessageHandler *handler)
 Read HTTP header from a binary string.
virtual bool WriteAsHttp (Writer *writer, MessageHandler *handler) const
 Serialize HTTP headers in HTTP format so it can be re-parsed.

Static Public Member Functions

static void RemoveFromHeaders (const StringSetInsensitive &names, protobuf::RepeatedPtrField< NameValue > *headers)
 Removes all headers whose name is in |names|.

Protected Member Functions

void PopulateMap () const
 const is a lie, mutates map_.

Protected Attributes

scoped_ptr
< StringMultiMapInsensitive
map_
scoped_ptr< Proto > proto_

Detailed Description

template<class Proto>
class net_instaweb::Headers< Proto >

Read/write API for HTTP headers (shared base class)


Member Function Documentation

template<class Proto>
bool net_instaweb::Headers< Proto >::Lookup ( const StringPiece &  name,
ConstStringStarVector *  values 
) const

Lookup attributes with provided name. Attribute values are stored in values. Returns true iff there were any attributes with provided name.

Note that Lookup, though declared const, is NOT thread-safe. This is because it lazily generates a map.

Todo:
TODO(jmarantz): this is a problem waiting to happen, but I believe it will not be a problem in the immediate future. We can refactor our way around this problem by moving the Map to an explicit separate class that can be instantiated to assist with Lookups and Remove. But that should be done in a separate CL from the one I'm typing into now.
template<class Proto>
const char* net_instaweb::Headers< Proto >::Lookup1 ( const StringPiece &  name) const

Looks up a single attribute value. Returns NULL if the attribute is not found, or if more than one attribute is found.

template<class Proto>
virtual bool net_instaweb::Headers< Proto >::Remove ( const StringPiece &  name,
const StringPiece &  value 
) [virtual]

Remove headers by name and value. Return true if anything was removed. Note: If the original headers were: attr: val1 attr: val2 attr: val3 and you Remove(attr, val2), your new headers will be: attr: val1, val3 (if attr is a comma-separated field) and - attr: val1 attr: val3 (otherwise).

Reimplemented in net_instaweb::ResponseHeaders.

template<class Proto>
virtual bool net_instaweb::Headers< Proto >::RemoveAllFromSet ( const StringSetInsensitive &  names) [virtual]

Removes all headers whose name is in |names|. Return true if anything was removed.

Reimplemented in net_instaweb::ResponseHeaders.

template<class Proto>
void net_instaweb::Headers< Proto >::RemoveCookie ( const StringPiece &  cookie_name)

Remove all instances of cookie_name in all the cookie headers. Empty cookie headers will be removed. It might be better for performance if this function is called after checking that the cookie is present. CAVEAT: Double quoted values are not necessarily treated as one token. Please refer to the test cases in headers_cookie_util_test.cc for more details.

template<class Proto>
virtual void net_instaweb::Headers< Proto >::Replace ( const StringPiece &  name,
const StringPiece &  value 
) [virtual]

Similar to RemoveAll followed by Add. Note that the attribute order may be changed as a side effect of this operation.

Reimplemented in net_instaweb::ResponseHeaders.

template<class Proto>
virtual void net_instaweb::Headers< Proto >::UpdateFrom ( const Headers< Proto > &  other) [virtual]

Merge headers. Replaces all headers specified both here and in other with the version in other. Useful for updating headers when recieving 304 Not Modified responses. Note: This is order-scrambling.

Reimplemented in net_instaweb::ResponseHeaders.


Member Data Documentation

template<class Proto>
scoped_ptr<StringMultiMapInsensitive> net_instaweb::Headers< Proto >::map_ [mutable, protected]

We have two represenations for the name/value pairs. The HttpResponseHeader protobuf contains a simple string-pair vector, but lacks a fast associative lookup. So we will build structures for associative lookup lazily, and keep them up-to-date if they are present.


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines