Wt  4.11.1
Public Member Functions | List of all members
Wt::Http::Response Class Reference

A resource response. More...

#include <Wt/Http/Response.h>

Public Member Functions

void setStatus (int status)
 Sets the response status. More...
 
void setContentLength (::uint64_t length)
 Sets the content length. More...
 
void setMimeType (const std::string &mimeType)
 Set the content mime type. More...
 
void addHeader (const std::string &name, const std::string &value)
 Add an HTTP header. More...
 
void insertHeader (const std::string &name, const std::string &value)
 Inserts an HTTP header. More...
 
ResponseContinuationcreateContinuation ()
 Create a continuation object for this response. More...
 
ResponseContinuationcontinuation () const
 Return the continuation, if one was created for this response. More...
 
std::ostream & out ()
 Returns the stream for getting the response output.
 

Detailed Description

A resource response.

This class defines the HTTP response for a WResource request.

More specifically you can:

You may chose to provide only a partial response. In that case, use createContinuation() to create a continuation object to which you can annotate information for the next request to process the response further.

See also
WResource::handleRequest(), Request

Member Function Documentation

◆ addHeader()

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

Add an HTTP header.

Headers may be added only before setting the content mime-type (setMimeType()), and before streaming any data to the out() stream.

◆ continuation()

ResponseContinuation * Wt::Http::Response::continuation ( ) const

Return the continuation, if one was created for this response.

Returns the continuation that was previously created using createContinuation(), or nullptr if no continuation was created yet.

See also
createContinuation()

◆ createContinuation()

ResponseContinuation * Wt::Http::Response::createContinuation ( )

Create a continuation object for this response.

A continuation is used to resume sending more data later for this response. There are two possible reasons for this:

  • the entire response is quite big and you may want to read and send it in smaller chunks to avoid memory consumption problems since the I/O layer buffers the response first in memory to send it then out to a possibly slow client using async I/O.
  • you may not have any more data available, currently, but expect more data later. In that case you can call ResponseContinuation::waitForMoreData() and later call WResource::haveMoreData() when more data is available.

A new call to handleRequest() will be made to retrieve more data.

See also
continuation()

◆ insertHeader()

void Wt::Http::Response::insertHeader ( const std::string &  name,
const std::string &  value 
)

Inserts an HTTP header.

Headers may be added only before setting the content mime-type (setMimeType()), and before streaming any data to the out() stream.

Inserting will differ from adding headers such that headers will not be duplicated. Rather, if a header with the same name exists, the value will be replaced with the name value.

Passing an empty value will clear the header if it already exists.

◆ setContentLength()

void Wt::Http::Response::setContentLength ( ::uint64_t  length)

Sets the content length.

If content length is known, use this method to set it. File downloads will see progress bars. If not set, Wt will use chunked transfers.

Always use this method instead of setting the Content-Length header with addHeader().

Headers may be added only before setting the content mime-type (setMimeType()), and before streaming any data to the out() stream.

◆ setMimeType()

void Wt::Http::Response::setMimeType ( const std::string &  mimeType)

Set the content mime type.

The content mimetype is used by the browser to correctly interpret the resource.

◆ setStatus()

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

Sets the response status.

Unless a overriden, 200 OK will be assumed.