Client Class Reference

#include <Pt/Http/Client.h>

An HTTP client. More...

Inherits Connectable, and NonCopyable.

Public Member Functions

 Client ()
 Default Constructor.
 
 Client (const Net::Endpoint &ep)
 Construct with host to connect to.
 
 Client (System::EventLoop &loop)
 Construct with event loop.
 
 Client (System::EventLoop &loop, const Net::Endpoint &ep)
 Construct with loop and host to connect to.
 
 ~Client ()
 Destructor.
 
System::EventLooploop () const
 Returns the used event loop.
 
void setActive (System::EventLoop &loop)
 Sets the event loop to use.
 
void setTimeout (std::size_t timeout)
 Set timeout for I/O operations.
 
void setSecure (Ssl::Context &ctx)
 Enable to use HTTPS.
 
void setPeerName (const std::string &peer)
 Set expected SSL peer name.
 
void setHost (const Net::Endpoint &ep)
 Set host to connect to.
 
void setHost (const Net::Endpoint &ep, const Net::TcpSocketOptions &opts)
 Set host to connect to.
 
const Net::Endpointhost () const
 Returns the host to connect to.
 
Requestrequest ()
 Returns the request to send.
 
const Requestrequest () const
 Returns the request to send.
 
Replyreply ()
 Returns the received reply.
 
const Replyreply () const
 Returns the received reply.
 
void beginSend (bool finished=true)
 Begin sending the request.
 
MessageProgress endSend ()
 End sending the request.
 
Signal< Client & > & requestSent ()
 Signals that a part of the request was sent.
 
void beginReceive ()
 Begin receiving the reply.
 
MessageProgress endReceive ()
 End receiving the reply.
 
Signal< Client & > & replyReceived ()
 Signals that a part of the reply was received.
 
void close ()
 Closes the connection and cancels all operations.
 
void send (bool finished=true)
 Blocks until request is sent.
 
std::istream & receive ()
 Blocks until reply is received.
 

Detailed Description

A connection will be persistent (keep-alive), if the request headers contains the keep-alive header fields. A persistent connection is needed for HTTP request pipelining. Once all requests have been made, the client should be closed, otherwise it may run into the servers keep-alive timeout, if the client is used again later.

// use client for multiple requests
...
// close the persistent connection
client.close();
Request & request()
Returns the request to send.
An HTTP client.
Definition: Client.h:78
void setKeepAlive()
Sets the HTTP keep-alive header.
MessageHeader & header()
Returns the header of the message.
Definition: Message.h:398