Hobrasoft httpd server
Embedded HTTP server for Qt and C++
httpconnection.h
Go to the documentation of this file.
1 
8 #ifndef _HttpConnection_H_
9 #define _HttpConnection_H_
10 
11 #include <QObject>
12 #include <QTcpSocket>
13 #include <QSslCertificate>
14 #include <QTimer>
15 #include <QDateTime>
16 #include <QHostAddress>
17 
18 namespace HobrasoftHttpd {
19 
20 class HttpRequest;
21 class HttpResponse;
22 class HttpRequestHandler;
23 class HttpServer;
24 class HttpSettings;
25 
26 
30 class HttpConnection : public QObject {
31  Q_OBJECT
32  public:
33 
34  ~HttpConnection();
35 
39  HttpConnection(HttpServer *parent, QTcpSocket *socket);
40 
56 
62  const HttpSettings *settings() const;
63 
69  HttpServer *httpServer() const { return m_parent; }
70 
74  QTcpSocket *socket() const { return m_socket; }
75 
79  bool verified() const { return m_verified; }
80 
81 
85  void setVerified(bool x) { m_verified = x; }
86 
92  void setPeerCertificate(const QSslCertificate&);
93 
97  QString commonName() const;
98 
102  const QSslCertificate peerCertificate() const { return m_peerCertificate; }
103 
107  bool isConnected() const { return m_connected; }
108 
109  void setTimeout(int x) { m_timeout->setInterval(x); startTimeout(); }
110 
114  QHostAddress peerAddress() const { return m_peerAddress; }
115 
116  HttpRequest *request() const { return m_request; }
117 
118 
119  QVariant webStatus() const;
120 
121  public slots:
127  void close();
128 
129  private slots:
130  #ifndef DOXYGEN_SHOULD_SKIP_THIS
131  void slotTimeout();
132  void slotRead();
133  void slotDisconnected();
134 
135  private:
136  void deleteRequest();
137  void startTimeout();
138  QTcpSocket *m_socket;
139  QTimer *m_timeout;
140  HttpRequest *m_request;
141  QList<HttpRequest *> m_requests;
142  HttpRequestHandler *m_handler;
143  HttpServer *m_parent;
144  QSslCertificate m_peerCertificate;
145  QHostAddress m_peerAddress;
146  bool m_connected;
147  bool m_inService;
148  bool m_verified;
149  #endif
150 
151 };
152 
153 }
154 
155 #endif
const HttpSettings * settings() const
Returns pointer to settings used in the class.
const QSslCertificate peerCertificate() const
Returns Peer&#39;s certificate.
HttpServer * httpServer() const
Returns pointer to http server.
QTcpSocket * socket() const
Returns the socket.
General single-threaded, event-driven HTTP server.
Definition: httpserver.h:88
Response to HTTP request - headers, cookies and body.
Definition: httpresponse.h:30
Configuration of the http server instance.
Definition: httpsettings.h:39
bool verified() const
Returns true if the client is verified using SSL.
HttpConnection(HttpServer *parent, QTcpSocket *socket)
Constructor is called automatically when new request arrived.
bool isConnected() const
Returns true if the connection is in connected state.
HttpResponse * response()
Returns new instance of class HttpResponse.
void close()
Closes the connection.
Processes HTTP request, parses headers, body and files sent by HTTP protocol.
Definition: httprequest.h:23
void setPeerCertificate(const QSslCertificate &)
Sets peer&#39;s certificate.
void setVerified(bool x)
Sets the flag verified.
QHostAddress peerAddress() const
Returns peer&#39;s host address.
Namespace of HTTP server.
QString commonName() const
Returns CommonName field from certificate.
One single connection to http server.