<commit_before>#ifndef __HTTP_H__
#define __HTTP_H__
// Copyright (c) 2009 - Decho Corp.

#include <string.h>
#include <map>
#include <set>
#include <stdexcept>
#include <vector>

#include "mordor/common/uri.h"
#include "mordor/common/version.h"

class HTTPException : public std::runtime_error
{
public:
    HTTPException()
        : std::runtime_error("")
    {}
    HTTPException(const std::string &message)
        : std::runtime_error(message)
    {}
};

namespace HTTP
{
    class IncompleteMessageHeaderException : public HTTPException
    {};

    // Unparseable
    class BadMessageHeaderException : public HTTPException
    {};

    class PriorRequestFailedException : public HTTPException
    {};

    class ConnectionVoluntarilyClosedException : public PriorRequestFailedException
    {};

    // Logically doesn't make sense
    class InvalidMessageHeaderException : public HTTPException
    {
    public:
        InvalidMessageHeaderException() {}
        InvalidMessageHeaderException(const std::string &message)
            : HTTPException(message)
        {}
    };

    class InvalidTransferEncodingException : public InvalidMessageHeaderException
    {
    public:
        InvalidTransferEncodingException(const std::string &message)
            : InvalidMessageHeaderException(message)
        {}
    };

    enum Method
    {
        GET,
        HEAD,
        POST,
        PUT,
        DELETE,
        CONNECT,
        OPTIONS,
        TRACE
    };
    extern const char *methods[];

    enum Status
    {
        INVALID                          = 0,

        CONTINUE                         = 100,
        SWITCHING_PROTOCOL               = 101,
        
        OK                               = 200,
        CREATED                          = 201,
        ACCEPTED                         = 202,
        NON_AUTHORITATIVE_INFORMATION    = 203,
        NO_CONTENT                       = 204,
        RESET_CONTENT                    = 205,
        PARTIAL_CONTENT                  = 206,

        MULTIPLE_CHOICES                 = 300,
        MOVED_PERMANENTLY                = 301,
        FOUND                            = 302,
        SEE_OTHER                        = 303,
        NOT_MODIFIED                     = 304,
        USE_PROXY                        = 305,
        // UNUSED                        = 306,
        TEMPORARY_REDIRECT               = 307,

        BAD_REQUEST                      = 400,
        UNAUTHORIZED                     = 401,
        PAYMENT_REQUIRED                 = 402,
        FORBIDDEN                        = 403,
        NOT_FOUND                        = 404,
        METHOD_NOT_ALLOWED               = 405,
        NOT_ACCEPTABLE                   = 406,
        PROXY_AUTHENTICATION_REQUIRED    = 407,
        REQUEST_TIMEOUT                  = 408,
        CONFLICT                         = 409,
        GONE                             = 410,
        LENGTH_REQUIRED                  = 411,
        PRECONDITION_FAILED              = 412,
        REQUEST_ENTITY_TOO_LARGE         = 413,
        REQUEST_URI_TOO_LONG             = 414,
        UNSUPPORTED_MEDIA_TYPE           = 415,
        REQUESTED_RANGE_NOT_SATISFIABLE  = 416,
        EXPECTATION_FAILED               = 417,

        INTERNAL_SERVER_ERROR            = 500,
        NOT_IMPLEMENTED                  = 501,
        BAD_GATEWAY                      = 502,
        SERVICE_UNAVAILABLE              = 503,
        GATEWAY_TIMEOUT                  = 504,
        HTTP_VERSION_NOT_SUPPORTED       = 505
    };
    const char *reason(Status s);

    std::string quote(const std::string &str, bool alwaysQuote = false);
    std::string unquote(const char *str, size_t size);
    std::string unquote(const std::string &str);

    struct Version
    {
        Version() : major(~0), minor(~0) {}
        Version(unsigned char m, unsigned char n) : major(m), minor(n) {}

        unsigned char major;<commit_msg>Handle 302 Found redirects on all Triton communication<commit_after>#ifndef __HTTP_H__
#define __HTTP_H__
// Copyright (c) 2009 - Decho Corp.

#include <string.h>
#include <map>
#include <set>
#include <stdexcept>
#include <vector>

#include "mordor/common/uri.h"
#include "mordor/common/version.h"

class HTTPException : public std::runtime_error
{
public:
    HTTPException()
        : std::runtime_error("")
    {}
    HTTPException(const std::string &message)
        : std::runtime_error(message)
    {}
};

namespace HTTP
{
    class IncompleteMessageHeaderException : public HTTPException
    {};

    // Unparseable
    class BadMessageHeaderException : public HTTPException
    {};

    class PriorRequestFailedException : public HTTPException
    {};

    class ConnectionVoluntarilyClosedException : public PriorRequestFailedException
    {};

    // Logically doesn't make sense
    class InvalidMessageHeaderException : public HTTPException
    {
    public:
        InvalidMessageHeaderException() {}
        InvalidMessageHeaderException(const std::string &message)
            : HTTPException(message)
        {}
    };

    class InvalidTransferEncodingException : public InvalidMessageHeaderException
    {
    public:
        InvalidTransferEncodingException(const std::string &message)
            : InvalidMessageHeaderException(message)
        {}
    };

    enum Method
    {
        GET,
        HEAD,
        POST,
        PUT,
        DELETE,
        CONNECT,
        OPTIONS,
        TRACE
    };
    extern const char *methods[];

    enum Status
    {
        INVALID                          = 0,

        CONTINUE                         = 100,
        SWITCHING_PROTOCOL               = 101,
        
        OK                               = 200,
        CREATED                          = 201,
        ACCEPTED                         = 202,
        NON_AUTHORITATIVE_INFORMATION    = 203,
        NO_CONTENT                       = 204,
        RESET_CONTENT                    = 205,
        PARTIAL_CONTENT                  = 206,

        MULTIPLE_CHOICES                 = 300,
        MOVED_PERMANENTLY                = 301,
        FOUND                            = 302,
        SEE_OTHER                        = 303,
        NOT_MODIFIED                     = 304,
        USE_PROXY                        = 305,
        // UNUSED                        = 306,
        TEMPORARY_REDIRECT               = 307,

        BAD_REQUEST                      = 400,
        UNAUTHORIZED                     = 401,
        PAYMENT_REQUIRED                 = 402,
        FORBIDDEN                        = 403,
        NOT_FOUND                        = 404,
        METHOD_NOT_ALLOWED               = 405,
        NOT_ACCEPTABLE                   = 406,
        PROXY_AUTHENTICATION_REQUIRED    = 407,
        REQUEST_TIMEOUT                  = 408,
        CONFLICT                         = 409,
        GONE                             = 410,
        LENGTH_REQUIRED                  = 411,
        PRECONDITION_FAILED              = 412,
        REQUEST_ENTITY_TOO_LARGE         = 413,
        REQUEST_URI_TOO_LONG             = 414,
        UNSUPPORTED_MEDIA_TYPE           = 415,
        REQUESTED_RANGE_NOT_SATISFIABLE  = 416,
        EXPECTATION_FAILED               = 417,

        INTERNAL_SERVER_ERROR            = 500,
        NOT_IMPLEMENTED                  = 501,
        BAD_GATEWAY                      = 502,
        SERVICE_UNAVAILABLE              = 503,
        GATEWAY_TIMEOUT                  = 504,
        HTTP_VERSION_NOT_SUPPORTED       = 505
    };
    const char *reason(Status s);

    class Redirect : public HTTPException
    {
    public:
        Redirect(Status status, const URI &uri)
            : m_status(status), m_uri(uri)
        {}

        Status status() const { return m_status; }
        const URI &uri() const { return m_uri; }

    private:
        Status m_status;
        URI m_uri;
    };

    std::string quote(const std::string &str, bool alwaysQuote = false);
    std::string unquote(const char *str, size_t size);
    std::string unquote(const std::string &str);

    struct Version
    {
        Version() : major(~0), minor(~0) {}
        Version(unsigned char m, unsigned char n) : major(m), minor(n) {}

        unsigned char major;
{'fraction_non_alphanumeric': 0.0715492277992278, 'fraction_numerical': 0.03173262548262548, 'mean_word_length': 1.3296795952782463, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4408013', 'n_tokens_mistral': 2521, 'n_tokens_neox': 2130, 'n_words': 460}