Google APIs Client Library for C++
HttpResponse Class Reference

Captures the response from HttpRequest invocations. More...

#include "client/transport/http_response.h"

List of all members.

Public Member Functions

 HttpResponse ()
 Standard constructor.
virtual ~HttpResponse ()
 Standard destructor.
virtual void Clear ()
 Clear the state and headers from the response.
const HttpRequestStaterequest_state () const
 Returns the current request state.
HttpRequestState::StateCode request_state_code () const
 Returns the state code indicating where in the processing lifecycle the request currently is.
HttpRequestStatemutable_request_state ()
 Get modifiable request state.
void set_body_reader (DataReader *reader)
 Sets the reader for the message body in the HTTP response.
void set_body_writer (DataWriter *writer)
 Sets the writer for the message body in the HTTP response.
DataWriterbody_writer ()
 Returns the current body writer.
DataReaderbody_reader () const
 Returns the reader for the HTTP message body.
util::Status GetBodyString (string *body)
 Reads the entire response HTTP message body as a string.
util::Status transport_status () const
 Returns the transport status.
util::Status status () const
 Returns the overall request status.
void set_http_code (int code)
 Sets the HTTP status code for the response.
int http_code () const
 Returns the HTTP status code returned with the HTTP response.
bool done () const
 Returns true if the request is done.
bool ok () const
 Returns true if the request is ok.
const HttpHeaderMultiMapheaders () const
 Returns the HTTP response headers.
void AddHeader (const StringPiece &name, const StringPiece &value)
 Adds a response header seen in the HTTP response message.
void ClearHeaders ()
 Removes all the response headers from this instance.
const string * FindHeaderValue (const StringPiece &name) const
 Get the value of the named header.
bool WaitUntilDone (int64 timeout_ms=kint64max)
 Blocks the callers thread until this response is done() or the specified timeout expires.

Detailed Description

Captures the response from HttpRequest invocations.

HttpResponse has thread-safe state except the message body is not thread-safe. It is assumed that you will have only one body reader since DataReader is not thread-safe either and can only be reliably read one time.

Responses are typically created and owned by HttpRequest objects rather than directly by consumer code.

See also:
HttpRequest
HttpRequestState
body_reader
set_body_writer

Constructor & Destructor Documentation

Standard constructor.

virtual ~HttpResponse ( ) [virtual]

Standard destructor.


Member Function Documentation

void AddHeader ( const StringPiece &  name,
const StringPiece &  value 
) [inline]

Adds a response header seen in the HTTP response message.

Parameters:
[in]nameThe header name is not necessarily unique.
[in]valueThe value for the header.
DataReader* body_reader ( ) const [inline]

Returns the reader for the HTTP message body.

This method is not thread safe until the request is done.

Reading the response from the reader will update the position. The reader is not required to support Reset() so you may only have one chance to look at the response.

DataWriter* body_writer ( ) [inline]

Returns the current body writer.

virtual void Clear ( ) [virtual]

Clear the state and headers from the response.

void ClearHeaders ( ) [inline]

Removes all the response headers from this instance.

bool done ( ) const [inline]

Returns true if the request is done.

See also:
HttpRequestState::done()
const string* FindHeaderValue ( const StringPiece &  name) const

Get the value of the named header.

Returns:
NULL if the named header is not present, otherwise returns a pointer to the header value.

A non-NULL result will only be valid until a header is added or removed (or the object is destroyed).

util::Status GetBodyString ( string *  body)

Reads the entire response HTTP message body as a string.

If the body_reader was already accessed, including calling this method before, then this method might not work if the reader was not resetable. It will attempt to return the whole body as a string even if the body_reader() already read some portion of it.

Parameters:
[out]bodyThe entire message body text.
Returns:
status indicating whether the entire body could be read or not.

This method will block until the body_reader() is done reading.

const HttpHeaderMultiMap& headers ( ) const [inline]

Returns the HTTP response headers.

Returns:
individual headers might have multiple values.
int http_code ( ) const [inline]

Returns the HTTP status code returned with the HTTP response.

Returns:
0 if no response has been received yet.

Get modifiable request state.

this is not normally used when using requests but may be needed if you are using responses in some other non-standard way.

bool ok ( ) const [inline]

Returns true if the request is ok.

See also:
HttpRequestState::ok()
const HttpRequestState& request_state ( ) const [inline]

Returns the current request state.

Returns the state code indicating where in the processing lifecycle the request currently is.

void set_body_reader ( DataReader reader)

Sets the reader for the message body in the HTTP response.

Normally this is called by the HttpRequest::DoExecute() method.

Parameters:
[in]readerTakes owenership.
void set_body_writer ( DataWriter writer)

Sets the writer for the message body in the HTTP response.

This must be set before you call HttpRequest::Execute(). The response will be constructed with a writer such as NewStringDataWriter(). However, if you are expecting a large response and wish to stream it directly to a file (or some other type of writer) then you this is how you make that happen.

Parameters:
[in]writerTakes ownership.
void set_http_code ( int  code) [inline]

Sets the HTTP status code for the response.

Parameters:
[in]code0 indicates no code is available.
util::Status status ( ) const [inline]

Returns the overall request status.

See also:
HttpRequestState::transport_status()
util::Status transport_status ( ) const [inline]

Returns the transport status.

See also:
HttpRequestState::transport_status()
bool WaitUntilDone ( int64  timeout_ms = kint64max) [inline]

Blocks the callers thread until this response is done() or the specified timeout expires.

Note that if the underlying request was DestroyWhenDone then this response instance may no longer exist when this method returns. Also note that if the request was asynchronous, and the method returns true, then the callback (if any) has already finished running as well.

Parameters:
[in]timeout_msThe timeout in millis.
Returns:
true if the call's timeout expired, false if the response is done().

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