Hobrasoft httpd server
Embedded HTTP server for Qt and C++
Public Member Functions | Private Slots | List of all members
HobrasoftHttpd::HttpResponse Class Reference

Response to HTTP request - headers, cookies and body. More...

#include <httpresponse.h>

Inheritance diagram for HobrasoftHttpd::HttpResponse:

Public Member Functions

 HttpResponse (HttpConnection *)
 Constructor sets default values for headers (status 200, OK)
 
void setHeader (const QString &name, const QString &value)
 Sets or rewrite one header.
 
void setHeader (const QString &name, int value)
 Sets or rewrite one header.
 
void setSendHeaders (bool send)
 Sets the header sending. More...
 
QMap< QString, QString > & headers ()
 Returns headers of the response in QMap.
 
void clearHeaders ()
 Clears all headers set.
 
const QMap< QString, HttpCookie > & cookies () const
 Returns cookies of the response in QMap.
 
HttpCookie cookie (const QString &name)
 Returns cookie.
 
void setStatus (int code, const QString &description=QString())
 Set the status code and the description of the response.
 
void write (const QByteArray &data)
 Writes data to response body. More...
 
void flushSocket ()
 Flushed sockets data to network.
 
void flush ()
 Writes last part of the response and closes the socket when possible. More...
 
void setCookie (const HttpCookie &cookie)
 Sets a cookie.
 
bool containsHeader (const QString &name)
 Returns true if headers contains specific header.
 
bool chunked ()
 Returns true if the trasport mode is chunked.
 
bool isConnected () const
 Returns true if the http connection is in connected state.
 
void flushAndClose ()
 
void flushAndDelete ()
 
void close ()
 Closes socket and destroys connection. Should by called only when "chunked" transport is choosen. More...
 

Private Slots

void slotWrite (bool startTimer=true)
 
void socketDisconnected ()
 
void socketError (QAbstractSocket::SocketError)
 

Detailed Description

Response to HTTP request - headers, cookies and body.

Can send responses of chunked and regular type.

It is possible to send more responses to one request. In fact, this is the common practice when using HTML5 event streams.

Definition at line 30 of file httpresponse.h.

Member Function Documentation

◆ close()

void HttpResponse::close ( )

Closes socket and destroys connection. Should by called only when "chunked" transport is choosen.

Call flush() befor the close;

Definition at line 188 of file httpresponse.cpp.

◆ flush()

void HttpResponse::flush ( )

Writes last part of the response and closes the socket when possible.

When sending chunked response the last chunk is written (zero length), in other case the socket is closed.

Closing socket destroys the HttpConnection and HttpResponse classes.

Definition at line 235 of file httpresponse.cpp.

◆ setSendHeaders()

void HobrasoftHttpd::HttpResponse::setSendHeaders ( bool  send)
inline

Sets the header sending.

When the response is of chunked type, the headers are sent only once even if multiple responses are sent to one request. You can suppress the headers sending for the request.

Parameters
send- when set the headers are send (default), otherwise the headers are not send in response

Definition at line 59 of file httpresponse.h.

◆ write()

void HttpResponse::write ( const QByteArray &  data)

Writes data to response body.

Important note to chunked transport: write complete response at once. Every call of this method sends one chunk to the browser. You should write complete response to your own buffer and send the response in one call of this method.

Definition at line 200 of file httpresponse.cpp.


The documentation for this class was generated from the following files: