tufao  1.3.0
An asynchronous web framework for C++ built on top of Qt
httpserver.h
1 /*
2  Copyright (c) 2012 Vinícius dos Santos Oliveira
3 
4  Permission is hereby granted, free of charge, to any person obtaining a copy
5  of this software and associated documentation files (the "Software"), to deal
6  in the Software without restriction, including without limitation the rights
7  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8  copies of the Software, and to permit persons to whom the Software is
9  furnished to do so, subject to the following conditions:
10 
11  The above copyright notice and this permission notice shall be included in all
12  copies or substantial portions of the Software.
13 
14  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20  SOFTWARE.
21  */
22 
23 #ifndef TUFAO_SERVER_H
24 #define TUFAO_SERVER_H
25 
26 #include <functional>
27 #include <QtNetwork/QTcpServer>
28 #include "tufao_global.h"
29 
30 class QAbstractSocket;
31 
32 namespace Tufao {
33 
34 class HttpServerRequest;
35 class HttpServerResponse;
36 
54 class TUFAO_EXPORT HttpServer : public QObject
55 {
56  Q_OBJECT
57 public:
68  typedef std::function<void(HttpServerRequest &request, const QByteArray&)>
70 
76  explicit HttpServer(QObject *parent = 0);
77 
81  ~HttpServer();
82 
99  bool listen(const QHostAddress &address = QHostAddress::Any,
100  quint16 port = 0);
101 
105  bool isListening() const;
106 
114  quint16 serverPort() const;
115 
127  void setTimeout(int msecs = 0);
128 
132  int timeout() const;
133 
153  void setUpgradeHandler(UpgradeHandler functor);
154 
163  static UpgradeHandler defaultUpgradeHandler();
164 
165 signals:
191  void requestReady(Tufao::HttpServerRequest &request,
192  Tufao::HttpServerResponse &response);
193 
194 public slots:
199  void close();
200 
201 protected:
209  void handleConnection(QAbstractSocket *connection);
210 
221  virtual void incomingConnection(qintptr socketDescriptor);
222 
241  virtual void checkContinue(HttpServerRequest &request,
242  HttpServerResponse &response);
243 
244 private slots:
245  void onNewConnection(qintptr socketDescriptor);
246  void onRequestReady();
247  void onUpgrade();
248 
249 private:
250  struct Priv;
251  Priv *priv;
252 };
253 
254 } // namespace Tufao
255 
256 #endif // TUFAO_SERVER_H
The Tufao::HttpServerResponse is used to respond to a Tufao::HttpServerRequest.
Definition: httpserverresponse.h:142
The Tufao::HttpServer represents a HTTP request received by Tufao::HttpServer.
Definition: httpserverrequest.h:54
This is the namespace where all Tufão facilities are grouped.
Definition: abstracthttpserverrequesthandler.h:30
std::function< void(HttpServerRequest &request, const QByteArray &)> UpgradeHandler
A typedef to http upgrade request handler.
Definition: httpserver.h:69
The Tufao::HttpServer class provides an implementation of the HTTP protocol.
Definition: httpserver.h:54