Skip to content
Snippets Groups Projects
Select Git revision
  • 0273fa035660f91646705d969b10c9d451e69c32
  • master default protected
  • release/202005
  • release/202001
  • release/201912
  • release/201911
  • release/releaseWindowsTestOne
  • release/windowsReleaseTest
  • release/releaseTest
  • release/releaseWindowsTest
  • release/201910
  • release/qt/201910
  • release/windows-test/201910
  • release/201908
  • release/201906
  • release/201905
  • release/201904
  • release/201903
  • release/201902
  • release/201901
  • release/201812
  • 4.0.0
  • 2.2.0
  • 2.1.0
  • 2.0.1
  • 2.0.0
  • 1.4.1
  • 1.4.0
  • 1.3.0
  • 1.2.0
  • 1.1.0
31 results

array_size.h

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    http.cpp 37.35 KiB
    /*
     *  Copyright (C) 2016-2019 Savoir-faire Linux Inc.
     *  Author: Vsevolod Ivanov <vsevolod.ivanov@savoirfairelinux.com>
     *
     *  This program is free software; you can redistribute it and/or modify
     *  it under the terms of the GNU General Public License as published by
     *  the Free Software Foundation; either version 3 of the License, or
     *  (at your option) any later version.
     *
     *  This program 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 General Public License for more details.
     *
     *  You should have received a copy of the GNU General Public License
     *  along with this program. If not, see <https://www.gnu.org/licenses/>.
     */
    
    #include "http.h"
    #include "log_enable.h"
    #include "crypto.h"
    #include "base64.h"
    
    #include <asio.hpp>
    #include <restinio/impl/tls_socket.hpp>
    #include <http_parser.h>
    #include <json/json.h>
    
    namespace dht {
    namespace http {
    
    constexpr char HTTP_HEADER_CONNECTION[] = "Connection";
    constexpr char HTTP_HEADER_CONNECTION_KEEP_ALIVE[] = "keep-alive";
    constexpr char HTTP_HEADER_CONNECTION_CLOSE[] = "close";
    constexpr char HTTP_HEADER_CONTENT_LENGTH[] = "Content-Length";
    constexpr char HTTP_HEADER_CONTENT_TYPE_JSON[] = "application/json";
    constexpr char HTTP_HEADER_TRANSFER_ENCODING[] = "Transfer-Encoding";
    constexpr char HTTP_HEADER_TRANSFER_ENCODING_CHUNKED[] = "chunked";
    constexpr char HTTP_HEADER_DELIM[] = "\r\n\r\n";
    constexpr char BODY_VALUE_DELIM = '\n';
    
    Url::Url(const std::string& url): url(url)
    {
        size_t addr_begin = 0;
        // protocol
        const size_t proto_end = url.find("://");
        if (proto_end != std::string::npos){
            addr_begin = proto_end + 3;
            if (url.substr(0, proto_end) == "https"){
                protocol = "https";
                service = protocol;
            }
        }
        // host and service
        size_t addr_size = url.substr(addr_begin).find("/");
        if (addr_size == std::string::npos)
            addr_size = url.size() - addr_begin;
        auto host_service = splitPort(url.substr(addr_begin, addr_size));
        host = host_service.first;
        if (!host_service.second.empty())
            service = host_service.second;
        // target, query and fragment
        size_t query_begin = url.find("?");
        auto addr_end = addr_begin + addr_size;
        if (addr_end < url.size())
            target = url.substr(addr_end);
        size_t fragment_begin = url.find("#");
        if (fragment_begin == std::string::npos){
            query = url.substr(query_begin + 1);
        } else {