Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
net_instaweb::Headers< Proto > Class Template Reference

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

#include "headers.h"

Public Types

typedef std::pair< StringPiece,
StringPiece > 
ValueAndAttributes
 typedef's for manipulating the cookie multimap.
 
typedef std::multimap
< StringPiece,
ValueAndAttributes
CookieMultimap
 
typedef std::multimap
< StringPiece,
ValueAndAttributes >
::const_iterator 
CookieMultimapConstIter
 

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
 
void SetValue (int i, StringPiece value)
 
bool Lookup (const StringPiece &name, ConstStringStarVector *values) const
 
GoogleString LookupJoined (StringPiece name) 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)
 
void Add (const StringPiece &name, const StringPiece &value)
 
bool Remove (const StringPiece &name, const StringPiece &value)
 
bool RemoveAll (const StringPiece &name)
 Removes all headers by name. Return true if anything was removed.
 
bool RemoveAllFromSortedArray (const StringPiece *names, int names_size)
 
bool RemoveAllWithPrefix (const StringPiece &prefix)
 
bool RemoveIfNotIn (const Headers &keep)
 
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.
 
void CopyToProto (Proto *proto) const
 Copy protobuf representation to "proto".
 

Static Public Member Functions

template<class StringType >
static bool RemoveFromHeaders (const StringType *names, int names_size, protobuf::RepeatedPtrField< NameValue > *headers)
 
static bool FindValueForName (const StringPieceVector &name_equals_value_vec, StringPiece name_to_find, StringPiece *optional_retval)
 
static bool ExtractNameAndValue (StringPiece input, StringPiece *name, StringPiece *optional_retval)
 

Protected Member Functions

void SetProto (Proto *proto)
 You need to know what you're doing to use these, so for subclasses only. More...
 
void CopyProto (const Proto &proto)
 
void PopulateMap () const
 const is a lie, mutates map_.
 
const CookieMultimap * PopulateCookieMap (StringPiece header_name) const
 
virtual void UpdateHook ()
 
const Proto * proto () const
 
Proto * mutable_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>
void net_instaweb::Headers< Proto >::Add ( const StringPiece &  name,
const StringPiece &  value 
)

Adds a new header, even if a header with the 'name' exists already. Note that this does not add a new entry to a comma-separated list for headers that are ordinarily represented that way, but that the semantics will be the same.

template<class Proto>
static bool net_instaweb::Headers< Proto >::ExtractNameAndValue ( StringPiece  input,
StringPiece *  name,
StringPiece *  optional_retval 
)
static

Parse a name[=value] string and extract the name and value (if the given argument isn't NULL) with leading and trailing whitespace removed. Returns true if a value was assigned (specifically, an '=' was found), else false.

template<class Proto>
static bool net_instaweb::Headers< Proto >::FindValueForName ( const StringPieceVector &  name_equals_value_vec,
StringPiece  name_to_find,
StringPiece *  optional_retval 
)
static

Check the given vector of name[=value] strings for an entry with the given name, returning true iff found and setting optional_retval iff it is not NULL and there is a value assigned (there is an '=' in the string). Note: only the value of the first occurence of name is returned. Note: the return value is trimmed of leading and trailing whitespace. Note: the return value might be assigned to even if we return false.

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. Attributes that normally appear as a comma-separated header list (Cache-Control, Accept, etc.) will yield multiple entries in *values. Multiple occurrences of a header (Cookie, etc.) will also yield multiple entries in *values. In most cases (but not Cookies) the semantics are equivalent either way. See: http://tools.ietf.org/html/draft-ietf-httpbis-p1-messaging-26#section-3.2.2

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 (either multiple comma-separated entries, or multiple copies of the header).

template<class Proto>
GoogleString net_instaweb::Headers< Proto >::LookupJoined ( StringPiece  name) const

Synthesize a string that represents what all the values a header would serialize to. Returns "" if the header isn't present.

Same constness warnings as for ResponseHeaders::Lookup() apply.

template<class Proto>
const CookieMultimap* net_instaweb::Headers< Proto >::PopulateCookieMap ( StringPiece  header_name) const
protected

Populates the cookies map and returns a const pointer to it. 'name' is the name of the header to lookup: either "Cookie" for request headers or "Set-Cookie" for response headers. The header is assumed to contain semi- colon separated name=value pairs. For "Set-Cookie" headers, the first pair is the name and value of the cookie and subsequent pairs are attributes of that cookie - the value will be the 'first' part of the pair in the map, all the attributes will be the 'second' part (as a single string of semi- colon separated name=value pairs). For "Cookie" headers, each pair is an independent cookie and is put into the map separately. Note that const is a lie: cookies_ is mutated.

template<class Proto>
const Proto* net_instaweb::Headers< Proto >::proto ( ) const
inlineprotected

Subclasses need to manipulate the proto_ member as its type and use is specific to the subclass.

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

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).

All instances of 'value' will be removed from 'name'.

template<class Proto>
bool net_instaweb::Headers< Proto >::RemoveAllFromSortedArray ( const StringPiece *  names,
int  names_size 
)

Removes all headers whose name is in |names|, which must be in case-insensitive sorted order.

template<class Proto>
bool net_instaweb::Headers< Proto >::RemoveAllWithPrefix ( const StringPiece &  prefix)

Removes all headers whose name starts with prefix. Returns true if anything was removed.

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>
template<class StringType >
static bool net_instaweb::Headers< Proto >::RemoveFromHeaders ( const StringType *  names,
int  names_size,
protobuf::RepeatedPtrField< NameValue > *  headers 
)
static

Removes all headers whose name is in |names|, which must be in string-insensitive sorted order. Returns true if anything was removed.

template<class Proto>
bool net_instaweb::Headers< Proto >::RemoveIfNotIn ( const Headers< Proto > &  keep)

Removes any headers from this that are not in 'keep', considering both names and values. Returns true if anything was removed.

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.

template<class Proto>
void net_instaweb::Headers< Proto >::SetProto ( Proto *  proto)
protected

You need to know what you're doing to use these, so for subclasses only.

Takes ownership of the argument.

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.

template<class Proto>
virtual void net_instaweb::Headers< Proto >::UpdateHook ( )
protectedvirtual

Called whenever a mutation occurrs. Subclasses may override to update any local copies of data.

Reimplemented in net_instaweb::ResponseHeaders.


The documentation for this class was generated from the following file: