23#ifndef QHTTPENGINE_SOCKET_H
24#define QHTTPENGINE_SOCKET_H
26#include <QHostAddress>
30#include <qhttpengine/ibytearray.h>
32#include "qhttpengine_export.h"
40class QHTTPENGINE_EXPORT SocketPrivate;
96class QHTTPENGINE_EXPORT
Socket :
public QIODevice
185 Socket(QTcpSocket *socket, QObject *parent = 0);
295 void setStatusCode(
int statusCode,
const QByteArray &statusReason = QByteArray());
304 void setHeader(
const QByteArray &name,
const QByteArray &value,
bool replace =
true);
330 void writeError(
int statusCode,
const QByteArray &statusReason = QByteArray());
335 void writeJson(
const QJsonDocument &document,
int statusCode =
OK);
359 virtual qint64
readData(
char *data, qint64 maxlen);
368 SocketPrivate *
const d;
369 friend class SocketPrivate;
Method
Definition socket.h:122
@ CONNECT
Proxy connection.
Definition socket.h:138
@ GET
Request resource.
Definition socket.h:126
@ DELETE
Delete resource.
Definition socket.h:134
@ PUT
Store resource.
Definition socket.h:132
@ TRACE
Diagnostic trace.
Definition socket.h:136
@ HEAD
Request resource without body.
Definition socket.h:128
@ POST
Store subordinate resource.
Definition socket.h:130
@ OPTIONS
Request for communications options.
Definition socket.h:124
@ BadRequest
Bad client request.
Definition socket.h:158
@ MethodNotAllowed
Method is not valid for the resource.
Definition socket.h:166
@ BadGateway
Invalid response from server while acting as a gateway.
Definition socket.h:172
@ InternalServerError
An internal server error occurred.
Definition socket.h:170
@ HttpVersionNotSupported
Server does not supports the HTTP version in the request
Definition socket.h:176
@ Created
Request was successful and a resource was created.
Definition socket.h:148
@ Forbidden
Access to the resource is forbidden.
Definition socket.h:162
@ MovedPermanently
Resource has moved permanently.
Definition socket.h:154
@ OK
Request was successful.
Definition socket.h:146
@ Found
Resource is available at an alternate URI.
Definition socket.h:156
@ NotFound
Resource was not found.
Definition socket.h:164
@ Conflict
The request could not be completed due to a conflict with the current state of the resource.
Definition socket.h:168
@ PartialContent
Range request was successful
Definition socket.h:152
@ Unauthorized
Client is unauthorized to access the resource.
Definition socket.h:160
@ Accepted
Request was accepted for processing, not completed yet.
Definition socket.h:150
@ ServiceUnavailable
Server unable to handle request due to overload
Definition socket.h:174
bool isHeadersParsed() const
Determine if the request headers have been parsed yet.
QHostAddress peerAddress() const
Retrive the address of the remote peer.
void writeRedirect(const QByteArray &path, bool permanent=false)
Write an HTTP 3xx redirect to the socket and close it.
virtual qint64 writeData(const char *data, qint64 len)
Implementation of QIODevice::writeData()
QString path() const
Retrieve the decoded path with the query string removed.
void setHeaders(const HeaderMap &headers)
Set the response headers.
virtual qint64 bytesAvailable() const
Retrieve the number of bytes available for reading.
virtual qint64 readData(char *data, qint64 maxlen)
Implementation of QIODevice::readData()
HeaderMap headers() const
Retrieve a map of request headers.
void writeJson(const QJsonDocument &document, int statusCode=OK)
Write the specified JSON document to the socket and close it.
void setStatusCode(int statusCode, const QByteArray &statusReason=QByteArray())
Set the response code.
QueryStringMap queryString() const
Retrieve the query string.
virtual void close()
Close the device and underlying socket.
QByteArray rawPath() const
Retrieve the raw request path.
QMultiMap< QString, QString > QueryStringMap
Map consisting of query string values.
Definition socket.h:105
void writeHeaders()
Write response headers to the socket.
void headersParsed()
Indicate that request headers have been parsed.
virtual bool isSequential() const
Determine if the device is sequential.
void setHeader(const QByteArray &name, const QByteArray &value, bool replace=true)
Set a response header to a specific value.
bool readJson(QJsonDocument &document)
Parse the request body as a JSON document.
void writeError(int statusCode, const QByteArray &statusReason=QByteArray())
Write an HTTP error to the socket and close it.
QMultiMap< IByteArray, QByteArray > HeaderMap
Map consisting of HTTP headers.
Definition socket.h:114
Socket(QTcpSocket *socket, QObject *parent=0)
Create a new socket from a QTcpSocket.
qint64 contentLength() const
Retrieve the length of the content.
Method method() const
Retrieve the request method.
void disconnected()
Indicate that the client has disconnected.