Skip to content
Snippets Groups Projects
Select Git revision
  • f74a00cbf10b39d21d445c229afa613f54bc0e96
  • master default protected
  • nightly/20250722.0
  • beta/202507211539
  • stable/20250718.0
  • nightly/20250718.0
  • nightly/20250714.0
  • beta/202507141552
  • beta/202506161038
  • stable/20250613.0
  • nightly/20250613.0
  • beta/202506101658
  • stable/20250610.0
  • nightly/20250610.0
  • beta/202506091027
  • beta/202506061543
  • nightly/20250605.0
  • beta/202506051039
  • beta/202506051002
  • beta/202506041611
  • beta/202506041335
  • beta/202505231812
22 results

windows_daemon_deploy.cmake

Blame
  • Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    http.cpp 50.34 KiB
    /*
     *  Copyright (C) 2014-2022 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 "compat/os_cert.h"
    
    #include <asio.hpp>
    #include <restinio/impl/tls_socket.hpp>
    #include <http_parser.h>
    #include <json/json.h>
    
    #include <openssl/ocsp.h>
    #include <openssl/ssl.h>
    #include <openssl/asn1.h>
    #include <openssl/x509.h>
    #include <openssl/x509_vfy.h>
    
    #define MAXAGE_SEC (14*24*60*60)
    #define JITTER_SEC (60)
    #define OCSP_MAX_RESPONSE_SIZE (20480)
    #ifdef _WIN32
    #define timegm                 _mkgmtime
    #endif
    
    namespace dht {
    namespace http {
    
    constexpr const char HTTP_HEADER_CONTENT_TYPE_JSON[] = "application/json";
    constexpr const char HTTP_HEADER_DELIM[] = "\r\n\r\n";
    constexpr const char HTTP_PROTOCOL[] = "http://";
    constexpr const char HTTPS_PROTOCOL[] = "https://";
    constexpr const char ORIGIN_PROTOCOL[] = "//";
    constexpr unsigned MAX_REDIRECTS {5};
    
    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";
            }
        }
        // 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())