Google APIs Client Library for C++
|
Captures the response from HttpRequest invocations. More...
#include "client/transport/http_response.h"
Public Member Functions | |
HttpResponse () | |
Standard constructor. | |
virtual | ~HttpResponse () |
Standard destructor. | |
virtual void | Clear () |
Clear the state and headers from the response. | |
const HttpRequestState & | request_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. | |
HttpRequestState * | mutable_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. | |
DataWriter * | body_writer () |
Returns the current body writer. | |
DataReader * | body_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 HttpHeaderMultiMap & | headers () 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. |
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.
HttpResponse | ( | ) |
Standard constructor.
virtual ~HttpResponse | ( | ) | [virtual] |
Standard destructor.
void AddHeader | ( | const StringPiece & | name, |
const StringPiece & | value | ||
) | [inline] |
Adds a response header seen in the HTTP response message.
[in] | name | The header name is not necessarily unique. |
[in] | value | The 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.
const string* FindHeaderValue | ( | const StringPiece & | name | ) | const |
Get the value of the named header.
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.
[out] | body | The entire message body text. |
This method will block until the body_reader() is done reading.
const HttpHeaderMultiMap& headers | ( | ) | const [inline] |
Returns the HTTP response headers.
int http_code | ( | ) | const [inline] |
Returns the HTTP status code returned with the HTTP response.
HttpRequestState* mutable_request_state | ( | ) | [inline] |
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.
const HttpRequestState& request_state | ( | ) | const [inline] |
Returns the current request state.
HttpRequestState::StateCode request_state_code | ( | ) | const [inline] |
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.
[in] | reader | Takes 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.
[in] | writer | Takes ownership. |
void set_http_code | ( | int | code | ) | [inline] |
Sets the HTTP status code for the response.
[in] | code | 0 indicates no code is available. |
util::Status status | ( | ) | const [inline] |
Returns the overall request status.
util::Status transport_status | ( | ) | const [inline] |
Returns the 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.
[in] | timeout_ms | The timeout in millis. |