Read/write API for HTTP response headers. More...
#include "response_headers.h"
Public Member Functions | |
void | FixDateHeaders (int64 now_ms) |
virtual void | Clear () |
void | CopyFrom (const ResponseHeaders &other) |
virtual void | Add (const StringPiece &name, const StringPiece &value) |
Add a new header. | |
bool | MergeContentType (const StringPiece &content_type) |
virtual bool | Remove (const StringPiece &name, const StringPiece &value) |
Remove headers by name and value. | |
virtual bool | RemoveAll (const StringPiece &name) |
Remove all headers by name. | |
virtual bool | RemoveAllFromSet (const StringSetInsensitive &names) |
Remove all headers whose name is in |names|. | |
virtual void | Replace (const StringPiece &name, const StringPiece &value) |
virtual void | UpdateFrom (const Headers< HttpResponseHeaders > &other) |
virtual bool | WriteAsBinary (Writer *writer, MessageHandler *message_handler) |
Serialize HTTP response header to a binary stream. | |
virtual bool | ReadFromBinary (const StringPiece &buf, MessageHandler *handler) |
virtual bool | WriteAsHttp (Writer *writer, MessageHandler *handler) const |
Serialize HTTP response header in HTTP format so it can be re-parsed. | |
void | ComputeCaching () |
bool | IsCacheable () const |
bool | IsProxyCacheable () const |
int64 | CacheExpirationTimeMs () const |
void | SetDateAndCaching (int64 date_ms, int64 ttl_ms, const StringPiece &cache_control_suffix) |
void | SetDateAndCaching (int64 date_ms, int64 ttl_ms) |
void | SetTimeHeader (const StringPiece &header, int64 time_ms) |
Set a time-based header, converting ms since epoch to a string. | |
void | SetDate (int64 date_ms) |
void | SetLastModified (int64 last_modified_ms) |
void | SetCacheControlMaxAge (int64 ttl_ms) |
bool | Sanitize () |
Removes cookie headers, and returns true if any changes were made. | |
bool | headers_complete () const |
int | status_code () const |
bool | has_status_code () const |
void | set_status_code (const int code) |
const char * | reason_phrase () const |
void | set_reason_phrase (const StringPiece &reason_phrase) |
int64 | implicit_cache_ttl_ms () const |
void | set_implicit_cache_ttl_ms (const int64 ttl) |
int64 | last_modified_time_ms () const |
int64 | date_ms () const |
Timestamp from Date header. | |
bool | has_date_ms () const |
int64 | cache_ttl_ms () const |
bool | is_implicitly_cacheable () const |
GoogleString | ToString () const |
void | SetStatusAndReason (HttpStatus::Code code) |
Sets the status code and reason_phrase based on an internal table. | |
void | DebugPrint () const |
bool | IsErrorStatus () |
Returns true if our status denotes the request failing. | |
bool | IsServerErrorStatus () |
Returns true if our status denotes a server side error. | |
bool | IsGzipped () const |
Determines whether a response header is marked as gzipped. | |
bool | WasGzippedLast () const |
const ContentType * | DetermineContentType () const |
bool | IsHtmlLike () const |
Does this header have an HTML-like Content-Type (HTML, XHTML, ...). | |
GoogleString | DetermineCharset () const |
Get the charset. Empty string if none set in a Content-Type header. | |
void | DetermineContentTypeAndCharset (const ContentType **content_type_out, GoogleString *charset_out) const |
bool | ParseDateHeader (const StringPiece &attr, int64 *date_ms) const |
bool | IsDateLaterThan (int64 time_ms) const |
void | ParseFirstLine (const StringPiece &first_line) |
Parses the first line of an HTTP response, including the "HTTP/". | |
void | ParseFirstLineHelper (const StringPiece &first_line) |
Parses the first line of an HTTP response, skipping the "HTTP/". | |
void | set_first_line (int major_version, int minor_version, int status_code, const StringPiece &reason_phrase) |
Set whole first line. | |
bool | VaryCacheable () const |
bool | FindContentLength (int64 *content_length) |
Static Public Member Functions | |
static bool | ParseTime (const char *time_str, int64 *time_ms) |
Parses an arbitrary string into milliseconds since 1970. | |
Static Public Attributes | |
static const int64 | kImplicitCacheTtlMs = 5 * Timer::kMinuteMs |
Friends | |
class | ResponseHeadersTest |
Read/write API for HTTP response headers.
int64 net_instaweb::ResponseHeaders::CacheExpirationTimeMs | ( | ) | const |
Note(sligocki): I think CacheExpirationTimeMs will return 0 if !IsCacheable
void net_instaweb::ResponseHeaders::ComputeCaching | ( | ) |
Compute caching information. The current time is used to compute the absolute time when a cache resource will expire. The timestamp is in milliseconds since 1970. It is an error to call any of the accessors before ComputeCaching is called.
const ContentType* net_instaweb::ResponseHeaders::DetermineContentType | ( | ) | const |
Get ContentType. NULL if none set or it isn't in our predefined set of known content types.
void net_instaweb::ResponseHeaders::DetermineContentTypeAndCharset | ( | const ContentType ** | content_type_out, | |
GoogleString * | charset_out | |||
) | const |
Determine both the charset and content-type as above. See DetermineContentType() and DetermineCharset() for details. You may also pass in NULL for those of _out parameters you do not need (but in that case the individual functions would be more convenient)
bool net_instaweb::ResponseHeaders::FindContentLength | ( | int64 * | content_length | ) |
Finds Content-Length in the response headers, returning true and putting it in *content_length if successful.
void net_instaweb::ResponseHeaders::FixDateHeaders | ( | int64 | now_ms | ) |
This will set Date and (if supplied in the first place, Expires) header to now if the delta of date header wrt now_ms is more than a tolerance. Leaves the ComputeCaching state dirty if it came in dirty, or clean if it came in clean.
bool net_instaweb::ResponseHeaders::headers_complete | ( | ) | const [inline] |
bool net_instaweb::ResponseHeaders::IsDateLaterThan | ( | int64 | time_ms | ) | const [inline] |
Returns true if the date header is later than time_ms. Used in invalidation of http cache.
bool net_instaweb::ResponseHeaders::MergeContentType | ( | const StringPiece & | content_type | ) |
Merge the new content_type with what is already in the headers. Returns true if the existing content-type header was changed.
bool net_instaweb::ResponseHeaders::ParseDateHeader | ( | const StringPiece & | attr, | |
int64 * | date_ms | |||
) | const |
Parses a date header such as HttpAttributes::kDate or HttpAttributes::kExpires, returning the timestamp as number of milliseconds since 1970.
virtual bool net_instaweb::ResponseHeaders::ReadFromBinary | ( | const StringPiece & | buf, | |
MessageHandler * | handler | |||
) | [virtual] |
Read HTTP response header from a binary string. Note that this is distinct from HTTP response-header parsing, which is in ResponseHeadersParser.
Reimplemented from net_instaweb::Headers< HttpResponseHeaders >.
virtual void net_instaweb::ResponseHeaders::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 from net_instaweb::Headers< HttpResponseHeaders >.
void net_instaweb::ResponseHeaders::SetCacheControlMaxAge | ( | int64 | ttl_ms | ) |
Sets the cache-control max-age to the specified value leaving the remaining Cache-Control attributes the same. This also updates the Expires header appropriately. Note that all existing max-age values are removed.
void net_instaweb::ResponseHeaders::SetDateAndCaching | ( | int64 | date_ms, | |
int64 | ttl_ms, | |||
const StringPiece & | cache_control_suffix | |||
) |
Set Date, Cache-Control and Expires headers appropriately. If cache_control_suffix is provided it is appended onto the Cache-Control: "max-age=%d" string. For example, cache_control_suffix = ", private" or ", no-cache, no-store".
virtual void net_instaweb::ResponseHeaders::UpdateFrom | ( | const Headers< HttpResponseHeaders > & | 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: We must use Headers<HttpResponseHeaders> instead of ResponseHeaders so that we don't expose the base UpdateFrom (and to avoid "hiding" errors).
Reimplemented from net_instaweb::Headers< HttpResponseHeaders >.
bool net_instaweb::ResponseHeaders::VaryCacheable | ( | ) | const |
Returns whether or not we can cache these headers if we take into account the Vary: headers.
const int64 net_instaweb::ResponseHeaders::kImplicitCacheTtlMs = 5 * Timer::kMinuteMs [static] |
The number of milliseconds of cache TTL we assign to resources that are "likely cacheable" (e.g. images, js, css, not html) and have no explicit cache ttl or expiration date.