Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.0

0.6.0 / src / web / external / lib_core / proxy.lucb

#==============================================================================================
#
#   proxy - Core::ProxyData: a SOCKS5 proxy parsed from its URL
#
#   DESCRIPTION:
#       Port of the inline function of Libraries/LibCore/Proxy.h (lines 26-45), the LibCore
#       seam ProxyMappings uses.
#
#       Copyright (c) 2022, Ali Mohammad Pur <mpfard@serenityos.org>
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from Libraries/LibCore/Proxy.h:26 Core::ProxyData::parse_url.
pub func core_proxy_data_parse_url(url: const web_url.Url*) -> CoreProxyData!:
    var proxy_data = CoreProxyData()
    let scheme = web_url.url_scheme(url)
    if not ak.string_eq_string_view(&scheme, ak.sv("socks5")):
        error(ak.ak_error, "Unsupported proxy type")

    proxy_data.type_ = CoreProxyDataType.socks5

    let host = web_url.url_host(url) else error(ak.ak_error, "Invalid proxy host, must be an IPv4 address")
    match host.m_value:
        .i_pv4_address(address): proxy_data.host_ipv4 = address
        _: error(ak.ak_error, "Invalid proxy host, must be an IPv4 address")

    let port = web_url.url_port(url) else error(ak.ak_error, "Invalid proxy, must have a port")
    proxy_data.port = port

    return proxy_data