Reply Class Reference

#include <Pt/Http/Reply.h>

HTTP reply message. More...

Inherits Message.

Public Types

enum  StatusCode {
  Continue = 100 ,
  OK = 200 ,
  MultipleChoices = 300 ,
  BadRequest = 400 ,
  Unauthorized = 401 ,
  RequestEntityTooLarge = 413 ,
  InternalServerError = 500
}
 HTTP reply status code. More...

Public Member Functions

 Reply (Http::Connection &conn)
 Construct with connection.
void setStatus (unsigned code, const std::string &txt)
 Sets the HTTP status.
void setStatus (unsigned code, const char *txt)
 Sets the HTTP status.
unsigned statusCode () const
 Returns the HTTP status code.
const std::string & statusText () const
 Returns the HTTP status text.
void beginSend (bool finish=true)
 Begins sending the reply.
void clear ()
 Clears all content.
Connection & connection ()
 Returns the used connection.
MessageHeaderheader ()
 Returns the header of the message.
const MessageHeaderheader () const
 Returns the header of the message.
std::iostream & body ()
 Returns the body of the message.
std::size_t available () const
 Returns the number of bytes available to read.
std::size_t pending () const
 Returns the number of bytes pending to be written.
void discard ()
 Discards the message body.

Detailed Description

Reply is the Message a server sends and a client receives. It adds the status line: statusCode() and statusText(), set together with setStatus(). The default is 200 OK. The nested StatusCode enumeration names the codes the API uses in replies it generates, but setStatus() accepts any code.

On the client, the reply is Client::reply() after a receive step has made it available. Read body() when progress reports body bytes, and read the status when progress reports the header. On the server, the responder writes the reply and starts sending it with beginSend(). The completion flag is true when this is the last chunk of the body, and false when onWriteReply() should run again for more. Calling beginSend(true) finishes the reply and releases the responder.

clear() resets status, header and body so the same reply object can be used for another exchange.

Member Enumeration Documentation

◆ StatusCode

enum StatusCode
Enumerator
Continue 

Continue.

OK 

OK.

MultipleChoices 

Multiple choices for request.

BadRequest 

Bad request received.

Unauthorized 

Unauthorized access.

RequestEntityTooLarge 

Request entity too large

InternalServerError 

Internal server error occured.

Member Function Documentation

◆ beginSend()

void beginSend ( bool finish = true)

finish is true when this is the last chunk of the body.