Wt  4.11.0
Loading...
Searching...
No Matches
Classes | Public Member Functions | List of all members
Wt::Http::Message Class Reference

An HTTP client message (request or response). More...

#include <Wt/Http/Message.h>

Classes

class  Header
 An HTTP message header. More...
 

Public Member Functions

 Message ()
 Constructor.
 
 Message (std::vector< Header > headers)
 Constructor.
 
 Message (const Message &message)
 Copy constructor.
 
 ~Message ()=default
 Destructor.
 
Messageoperator= (const Message &other)
 Copy assignment operator.
 
void setStatus (int status)
 Sets the status code.
 
int status () const
 Returns the status code.
 
void setHeader (const std::string &name, const std::string &value)
 Sets a header value.
 
void addHeader (const std::string &name, const std::string &value)
 Adds a header value.
 
const std::vector< Header > & headers () const
 Returns the headers.
 
const std::string * getHeader (const std::string &name) const
 Returns a header value.
 
void addBodyText (const std::string &text)
 Concatenates body text.
 
std::string body () const
 Returns the body text.
 

Detailed Description

An HTTP client message (request or response).

This class implements a message that is sent or received by the HTTP Client.

It is not to be confused with Request and Response, which are involved in the web application server handling.

Constructor & Destructor Documentation

◆ Message() [1/2]

Wt::Http::Message::Message ( )

Constructor.

This creates an empty message, with an invalid status (-1), no headers and an empty body.

◆ Message() [2/2]

Wt::Http::Message::Message ( std::vector< Header headers)

Constructor.

This creates an empty message, with an invalid status (-1), an empty body and the given headers.

Member Function Documentation

◆ addBodyText()

void Wt::Http::Message::addBodyText ( const std::string &  text)

Concatenates body text.

Adds the text to the message body.

◆ addHeader()

void Wt::Http::Message::addHeader ( const std::string &  name,
const std::string &  value 
)

Adds a header value.

A header is added, even if a header with the same name already was present. This is allowed by HTTP only for certain headers (e.g. Set-Cookie).

See also
setHeader()

◆ body()

std::string Wt::Http::Message::body ( ) const

Returns the body text.

Returns the body text.

◆ getHeader()

const std::string * Wt::Http::Message::getHeader ( const std::string &  name) const

Returns a header value.

Returns 0 if no header with that name is found.

◆ setHeader()

void Wt::Http::Message::setHeader ( const std::string &  name,
const std::string &  value 
)

Sets a header value.

If a header with that value was already defined, it is replaced with the new value. Otherwise, the header is added.

See also
addHeader()

◆ setStatus()

void Wt::Http::Message::setStatus ( int  status)

Sets the status code.

Note
This method is probably not useful to you, since for a request it is ignored, and for a response it is set by the client.

◆ status()

int Wt::Http::Message::status ( ) const

Returns the status code.

This returns the HTTP status code of a response message. Typical values are 200 (OK) or 404 (Not found).