4 #include "httprequest.h"
9 #include <QSharedPointer>
15 class HttpConnection : public QObject
19 enum : int { LoopLimit = 100, };
22 HttpConnection(HttpServer *server, QTcpSocket *socket);
26 /*! ハンドラのattach()と接続されます。 */
27 void attach(QSharedPointer<HttpRequest> request);
30 void setup_connections(QTcpSocket *socket);
31 void delete_connections(QTcpSocket *socket);
32 void setup_connections(HttpHandler *handler);
33 void delete_connections(HttpHandler *handler);
38 // QTcpSocket -------------------------------------------------------------
41 // Handler ----------------------------------------------------------------
42 void onWriteSocket(QByteArray bytes);
46 void begin_response();
52 HttpRequestParser m_parser;
54 QList<QSharedPointer<HttpRequest> > m_requests;
55 QSharedPointer<HttpRequest> m_request;
57 HttpHandler *m_handler;
61 class HttpServer : public QObject
64 friend class HttpConnection;
67 HttpServer(QObject *parent);
69 bool listen(QList<quint16> ports, QHostAddress const &address = QHostAddress::LocalHost);
70 bool listen(quint16 port, QHostAddress const &address = QHostAddress::LocalHost);
73 void install(HttpModule *module);
78 void onNewConnection();
81 HttpHandler* create_handler(QByteArray method, QByteArray url);
82 void destroy_handler(HttpHandler *handler);
88 QMap<HttpHandler*, HttpModule*> m_handlers;
89 QList<HttpModule*> m_modules;
91 HttpHandler *m_handler;
95 #endif // HTTPSERVER_H