<commit_before>/*  This file is part of the Tufão project
    Copyright (C) 2011 <NAME> <<EMAIL>>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 3 of the License, or (at your option) any
    later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef TUFAO_SERVER_H
#define TUFAO_SERVER_H

#include <QtNetwork/QTcpServer>
#include "httpserverresponse.h"

class QAbstractSocket;

namespace Tufao {

class HttpServerRequest;
class HttpServerResponse;

namespace Priv {

struct HttpServer;

} // namespace Priv

/*!
  \brief The Tufao::HttpServer class provides an implementation of the HTTP
  protocol.

  The HTTP is stateless request-response based protoccol. It let you create
  distributed dynamic collaborative applications.

  To create a webserver, all you need to do is call Tufao::HttpServer::listen
  and handle the Tufao::HttpServer::requestReady signal.

  \code
#include <Tufao/HttpServer>

class WebServer: public QObject
{
    Q_OBJECT
public:
    explicit WebServer(QObject *parent = NULL) :
        QObject(parent),
        httpServer(new Tufao::HttpServer(this))
    {
        connect(httpServer,
                SIGNAL(requestReady(Tufao::HttpServerRequest*,Tufao::HttpServerResponse*),
                this,
                SLOT(handleRequest(Tufao::HttpServerRequest*,Tufao::HttpServerResponse*)));
        httpServer->listen(QHostAddress::Any, 8080);
    }

private slots:
    void handleRequest(Tufao::HttpServerRequest *request,
                       Tufao::HttpServerResponse *response)
    {
        response->writeHead(200);
        response->setHeader("Content-Type", "text/plain");
        response->write("Hello World\n");
        response->end();
    }

private:
    Tufao::HttpServer *httpServer;
};
  \endcode

  \sa
  Tufao::HttpServerRequest
  Tufao::HttpServerResponse
  */
class TUFAO_EXPORT HttpServer : public QObject
{
    Q_OBJECT
public:
    /*!
      Constructs a Tufao::HttpServer object.

      \p parent is passed to the QObject constructor.
      */
    explicit HttpServer(QObject *parent = 0);

    /*!
      Destroys the object.
      */
    ~HttpServer();

    /*!
      \brief Tells the server to listen for incoming connections on address
      \p address and port \p port.

      If \p port is 0, a port is chosen automatically. The default registered
      port to HTTP server is 80.

      If \p address is QHostAddress::Any, the server will listen on all network
      interfaces.

      \return true on success

      \sa
      Tufao::HttpServer::isListening
      Tufao::HttpServer::serverPort
      */
    bool listen(const QHostAddress &address = QHostAddress::Any,
                quint16 port = 0);

    /*!
      Returns true if the server is listening for incoming connections.
      */
    bool isListening() const;

    /*!
      Returns the server's port if the server is listening; otherwise returns 0.

      \sa
      Tufao::HttpServer::listen
      Tufao::HttpServer::isListening
      */
    quint16 serverPort() const;

    /*!
      Sets the timeout of new connections to \msecs miliseconds.

      If you set the timeout to 0, then timeout feature will be disabled. You
      shouldn't disable this feature to protect against DoS attacks.

      The default timeout is 2 minutes (120000 miliseconds).

      \note
      You should call this function before Tufao::HttpServer::listen.
      */
    void setTimeout(int msecs = 0);

    /*!
      Returns the current set timeout.
      */
    int timeout() const;

signals:
    /*!
      This signal is emitted each time there is request.

      \note
      There may be multiple requests per connection (in the case of keep-alive
      connections) and HttpServer reutilizes \p request objects, so you can't,
      as an example, create a map using \p request as key to identify sessions.

      \warning
      You MUST NOT delete \p request and \p response. \p request and \p response
      deleted when the connection closes. Additionally, \p response will also be
      deleted when you are done with it (eg., calling
      Tufao::HttpServerResponse::end).

      \param request An instance of Tufao::HttpServerRequest

      \param response An instance of Tufao::HttpServerResponse
      */
    void requestReady(Tufao::HttpServerRequest *request,
                      Tufao::HttpServerResponse *response);
<commit_msg>Added note on HttpServer::onRequestReady documentation<commit_after>/*  This file is part of the Tufão project
    Copyright (C) 2011 <NAME> <<EMAIL>>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 3 of the License, or (at your option) any
    later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef TUFAO_SERVER_H
#define TUFAO_SERVER_H

#include <QtNetwork/QTcpServer>
#include "httpserverresponse.h"

class QAbstractSocket;

namespace Tufao {

class HttpServerRequest;
class HttpServerResponse;

namespace Priv {

struct HttpServer;

} // namespace Priv

/*!
  \brief The Tufao::HttpServer class provides an implementation of the HTTP
  protocol.

  The HTTP is stateless request-response based protoccol. It let you create
  distributed dynamic collaborative applications.

  To create a webserver, all you need to do is call Tufao::HttpServer::listen
  and handle the Tufao::HttpServer::requestReady signal.

  \code
#include <Tufao/HttpServer>

class WebServer: public QObject
{
    Q_OBJECT
public:
    explicit WebServer(QObject *parent = NULL) :
        QObject(parent),
        httpServer(new Tufao::HttpServer(this))
    {
        connect(httpServer,
                SIGNAL(requestReady(Tufao::HttpServerRequest*,Tufao::HttpServerResponse*),
                this,
                SLOT(handleRequest(Tufao::HttpServerRequest*,Tufao::HttpServerResponse*)));
        httpServer->listen(QHostAddress::Any, 8080);
    }

private slots:
    void handleRequest(Tufao::HttpServerRequest *request,
                       Tufao::HttpServerResponse *response)
    {
        response->writeHead(200);
        response->setHeader("Content-Type", "text/plain");
        response->write("Hello World\n");
        response->end();
    }

private:
    Tufao::HttpServer *httpServer;
};
  \endcode

  \sa
  Tufao::HttpServerRequest
  Tufao::HttpServerResponse
  */
class TUFAO_EXPORT HttpServer : public QObject
{
    Q_OBJECT
public:
    /*!
      Constructs a Tufao::HttpServer object.

      \p parent is passed to the QObject constructor.
      */
    explicit HttpServer(QObject *parent = 0);

    /*!
      Destroys the object.
      */
    ~HttpServer();

    /*!
      \brief Tells the server to listen for incoming connections on address
      \p address and port \p port.

      If \p port is 0, a port is chosen automatically. The default registered
      port to HTTP server is 80.

      If \p address is QHostAddress::Any, the server will listen on all network
      interfaces.

      \return true on success

      \sa
      Tufao::HttpServer::isListening
      Tufao::HttpServer::serverPort
      */
    bool listen(const QHostAddress &address = QHostAddress::Any,
                quint16 port = 0);

    /*!
      Returns true if the server is listening for incoming connections.
      */
    bool isListening() const;

    /*!
      Returns the server's port if the server is listening; otherwise returns 0.

      \sa
      Tufao::HttpServer::listen
      Tufao::HttpServer::isListening
      */
    quint16 serverPort() const;

    /*!
      Sets the timeout of new connections to \msecs miliseconds.

      If you set the timeout to 0, then timeout feature will be disabled. You
      shouldn't disable this feature to protect against DoS attacks.

      The default timeout is 2 minutes (120000 miliseconds).

      \note
      You should call this function before Tufao::HttpServer::listen.
      */
    void setTimeout(int msecs = 0);

    /*!
      Returns the current set timeout.
      */
    int timeout() const;

signals:
    /*!
      This signal is emitted each time there is request.

      \note
      There may be multiple requests per connection (in the case of keep-alive
      connections) and HttpServer reutilizes \p request objects, so you can't,
      as an example, create a map using \p request as key to identify sessions.

      \warning
      You MUST NOT delete \p request and \p response. \p request and \p response
      deleted when the connection closes. Additionally, \p response will also be
      deleted when you are done with it (eg., calling
      Tufao::HttpServerResponse::end).

      \note
      If this is a POST request for a big file, you should increase the timeout
      for this individual request.

      \param request An instance of Tufao::HttpServerRequest

      \param response An instance of Tufao::HttpServerResponse
      */
    void requestReady(Tufao::HttpServerRequest *request,
                      Tufao::HttpServerResponse *response);

{'fraction_non_alphanumeric': 0.07537486162825803, 'fraction_numerical': 0.006239307638120157, 'mean_word_length': 2.764393939393939, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6153333', 'n_tokens_mistral': 2773, 'n_tokens_neox': 2652, 'n_words': 1034}