Changeset 230973 in webkit


Ignore:
Timestamp:
Apr 24, 2018 2:54:49 PM (6 years ago)
Author:
commit-queue@webkit.org
Message:

[Curl] Extract proxy settings into a separate class to hold advanced information.
https://bugs.webkit.org/show_bug.cgi?id=184714

It was simplely structure to hold proxy setting. To support advanced feature of proxy
such as authentication, more inteligent object is required to store intermediate state
or errors. That's why we've introduced new class for that purpose.

Patch by Basuke Suzuki <Basuke Suzuki> on 2018-04-24
Reviewed by Youenn Fablet.

No new tests because there's no new behavior.

  • platform/Curl.cmake:
  • platform/network/curl/CurlContext.cpp:

(WebCore::CurlHandle::enableProxyIfExists):
(WebCore::CurlContext::ProxyInfo::url const): Deleted.
(WebCore::CurlContext::setProxyInfo): Deleted.

  • platform/network/curl/CurlContext.h:

(WebCore::CurlContext::proxySettings const):
(WebCore::CurlContext::setProxySettings):
(WebCore::CurlContext::setProxyUserPass):
(WebCore::CurlContext::proxyInfo const): Deleted.
(WebCore::CurlContext::setProxyInfo): Deleted.

  • platform/network/curl/CurlProxySettings.cpp: Added.

(WebCore::CurlProxySettings::CurlProxySettings):
(WebCore::CurlProxySettings::rebuildUrl):
(WebCore::CurlProxySettings::setUserPass):
(WebCore::protocolIsInSocksFamily):
(WebCore::getProxyPort):
(WebCore::createProxyUrl):

  • platform/network/curl/CurlProxySettings.h: Added.

(WebCore::CurlProxySettings::CurlProxySettings):
(WebCore::CurlProxySettings::isEmpty const):
(WebCore::CurlProxySettings::mode const):
(WebCore::CurlProxySettings::url const):
(WebCore::CurlProxySettings::ignoreHosts const):
(WebCore::CurlProxySettings::user const):
(WebCore::CurlProxySettings::password const):

  • platform/network/curl/CurlRequest.cpp:

(WebCore::CurlRequest::didReceiveHeader):

  • platform/network/curl/CurlResponse.h:

(WebCore::CurlResponse::isolatedCopy const):

  • platform/network/curl/ResourceResponseCurl.cpp:

(WebCore::ResourceResponse::ResourceResponse):

Location:
trunk/Source/WebCore
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r230970 r230973  
     12018-04-24  Basuke Suzuki  <Basuke.Suzuki@sony.com>
     2
     3        [Curl] Extract proxy settings into a separate class to hold advanced information.
     4        https://bugs.webkit.org/show_bug.cgi?id=184714
     5
     6        It was simplely structure to hold proxy setting. To support advanced feature of proxy
     7        such as authentication, more inteligent object is required to store intermediate state
     8        or errors. That's why we've introduced new class for that purpose.
     9
     10        Reviewed by Youenn Fablet.
     11
     12        No new tests because there's no new behavior.
     13
     14        * platform/Curl.cmake:
     15        * platform/network/curl/CurlContext.cpp:
     16        (WebCore::CurlHandle::enableProxyIfExists):
     17        (WebCore::CurlContext::ProxyInfo::url const): Deleted.
     18        (WebCore::CurlContext::setProxyInfo): Deleted.
     19        * platform/network/curl/CurlContext.h:
     20        (WebCore::CurlContext::proxySettings const):
     21        (WebCore::CurlContext::setProxySettings):
     22        (WebCore::CurlContext::setProxyUserPass):
     23        (WebCore::CurlContext::proxyInfo const): Deleted.
     24        (WebCore::CurlContext::setProxyInfo): Deleted.
     25        * platform/network/curl/CurlProxySettings.cpp: Added.
     26        (WebCore::CurlProxySettings::CurlProxySettings):
     27        (WebCore::CurlProxySettings::rebuildUrl):
     28        (WebCore::CurlProxySettings::setUserPass):
     29        (WebCore::protocolIsInSocksFamily):
     30        (WebCore::getProxyPort):
     31        (WebCore::createProxyUrl):
     32        * platform/network/curl/CurlProxySettings.h: Added.
     33        (WebCore::CurlProxySettings::CurlProxySettings):
     34        (WebCore::CurlProxySettings::isEmpty const):
     35        (WebCore::CurlProxySettings::mode const):
     36        (WebCore::CurlProxySettings::url const):
     37        (WebCore::CurlProxySettings::ignoreHosts const):
     38        (WebCore::CurlProxySettings::user const):
     39        (WebCore::CurlProxySettings::password const):
     40        * platform/network/curl/CurlRequest.cpp:
     41        (WebCore::CurlRequest::didReceiveHeader):
     42        * platform/network/curl/CurlResponse.h:
     43        (WebCore::CurlResponse::isolatedCopy const):
     44        * platform/network/curl/ResourceResponseCurl.cpp:
     45        (WebCore::ResourceResponse::ResourceResponse):
     46
    1472018-04-24  Youenn Fablet  <youenn@apple.com>
    248
  • trunk/Source/WebCore/platform/Curl.cmake

    r229359 r230973  
    1717    platform/network/curl/CurlFormDataStream.cpp
    1818    platform/network/curl/CurlMultipartHandle.cpp
     19    platform/network/curl/CurlProxySettings.cpp
    1920    platform/network/curl/CurlRequest.cpp
    2021    platform/network/curl/CurlRequestScheduler.cpp
  • trunk/Source/WebCore/platform/network/curl/CurlContext.cpp

    r230620 r230973  
    11/*
    22 * Copyright (C) 2013 Apple Inc.  All rights reserved.
    3  * Copyright (C) 2017 Sony Interactive Entertainment Inc.
     3 * Copyright (C) 2018 Sony Interactive Entertainment Inc.
    44 *
    55 * Redistribution and use in source and binary forms, with or without
     
    139139}
    140140
    141 // Proxy =======================
    142 
    143 const String CurlContext::ProxyInfo::url() const
    144 {
    145     String userPass;
    146     if (username.length() || password.length())
    147         userPass = username + ":" + password + "@";
    148 
    149     return String("http://") + userPass + host + ":" + String::number(port);
    150 }
    151 
    152 void CurlContext::setProxyInfo(const String& host,
    153     unsigned long port,
    154     CurlProxyType type,
    155     const String& username,
    156     const String& password)
    157 {
    158     ProxyInfo info;
    159 
    160     info.host = host;
    161     info.port = port;
    162     info.type = type;
    163     info.username = username;
    164     info.password = password;
    165 
    166     setProxyInfo(info);
    167 }
    168 
    169141bool CurlContext::isHttp2Enabled() const
    170142{
     
    513485void CurlHandle::enableProxyIfExists()
    514486{
    515     auto& proxy = CurlContext::singleton().proxyInfo();
    516 
    517     if (proxy.type != CurlProxyType::Invalid) {
     487    auto& proxy = CurlContext::singleton().proxySettings();
     488
     489    switch (proxy.mode()) {
     490    case CurlProxySettings::Mode::Default :
     491        // For the proxy set by environment variable
     492        if (!proxy.user().isEmpty())
     493            curl_easy_setopt(m_handle, CURLOPT_PROXYUSERNAME, proxy.user().utf8().data());
     494        if (!proxy.password().isEmpty())
     495            curl_easy_setopt(m_handle, CURLOPT_PROXYPASSWORD, proxy.password().utf8().data());
     496        curl_easy_setopt(m_handle, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
     497        break;
     498    case CurlProxySettings::Mode::NoProxy :
     499        // Disable the use of a proxy, even if there is an environment variable set for it.
     500        curl_easy_setopt(m_handle, CURLOPT_PROXY, "");
     501        break;
     502    case CurlProxySettings::Mode::Custom :
    518503        curl_easy_setopt(m_handle, CURLOPT_PROXY, proxy.url().utf8().data());
    519         curl_easy_setopt(m_handle, CURLOPT_PROXYTYPE, proxy.type);
     504        curl_easy_setopt(m_handle, CURLOPT_NOPROXY, proxy.ignoreHosts().utf8().data());
     505        curl_easy_setopt(m_handle, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
     506        break;
    520507    }
    521508}
  • trunk/Source/WebCore/platform/network/curl/CurlContext.h

    r230303 r230973  
    11/*
    22 * Copyright (C) 2013 Apple Inc.  All rights reserved.
    3  * Copyright (C) 2017 Sony Interactive Entertainment Inc.
     3 * Copyright (C) 2018 Sony Interactive Entertainment Inc.
    44 *
    55 * Redistribution and use in source and binary forms, with or without
     
    2727#pragma once
    2828
     29#include "CurlProxySettings.h"
    2930#include "CurlSSLHandle.h"
    3031#include "URL.h"
     
    4445
    4546namespace WebCore {
    46 
    47 enum class CurlProxyType {
    48     Invalid = -1,
    49     HTTP = CURLPROXY_HTTP,
    50     Socks4 = CURLPROXY_SOCKS4,
    51     Socks4A = CURLPROXY_SOCKS4A,
    52     Socks5 = CURLPROXY_SOCKS5,
    53     Socks5Hostname = CURLPROXY_SOCKS5_HOSTNAME
    54 };
    5547
    5648// Values taken from http://www.browserscope.org/ following
     
    10395    friend NeverDestroyed<CurlContext>;
    10496public:
    105     struct ProxyInfo {
    106         String host;
    107         unsigned long port;
    108         CurlProxyType type { CurlProxyType::Invalid };
    109         String username;
    110         String password;
    111 
    112         const String url() const;
    113     };
    114 
    11597    WEBCORE_EXPORT static CurlContext& singleton();
    11698
     
    122104
    123105    // Proxy
    124     const ProxyInfo& proxyInfo() const { return m_proxy; }
    125     void setProxyInfo(const ProxyInfo& info) { m_proxy = info; }
    126     void setProxyInfo(const String& host = emptyString(), unsigned long port = 0, CurlProxyType = CurlProxyType::HTTP, const String& username = emptyString(), const String& password = emptyString());
     106    const CurlProxySettings& proxySettings() const { return m_proxySettings; }
     107    void setProxySettings(const CurlProxySettings& settings) { m_proxySettings = settings; }
     108    void setProxyUserPass(const String& user, const String& password) { m_proxySettings.setUserPass(user, password); }
    127109
    128110    // SSL
     
    145127    void initShareHandle();
    146128
    147     ProxyInfo m_proxy;
     129    CurlProxySettings m_proxySettings;
    148130    CurlShareHandle m_shareHandle;
    149131    CurlSSLHandle m_sslHandle;
  • trunk/Source/WebCore/platform/network/curl/CurlRequest.cpp

    r230734 r230973  
    313313    m_response.url = m_request.url();
    314314    m_response.statusCode = statusCode;
     315    m_response.httpConnectCode = httpConnectCode;
    315316
    316317    if (auto length = m_curlHandle->getContentLength())
  • trunk/Source/WebCore/platform/network/curl/CurlResponse.h

    r226754 r230973  
    11/*
    2  * Copyright (C) 2017 Sony Interactive Entertainment Inc.
     2 * Copyright (C) 2018 Sony Interactive Entertainment Inc.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    4040        copy.url = url.isolatedCopy();
    4141        copy.statusCode = statusCode;
     42        copy.httpConnectCode = httpConnectCode;
    4243        copy.expectedContentLength = expectedContentLength;
    4344
     
    5455    URL url;
    5556    long statusCode { 0 };
     57    long httpConnectCode { 0 };
    5658    long long expectedContentLength { 0 };
    5759    Vector<String> headers;
  • trunk/Source/WebCore/platform/network/curl/ResourceResponseCurl.cpp

    r226754 r230973  
    11/*
    2  * Copyright (C) 2017 Sony Interactive Entertainment Inc.
     2 * Copyright (C) 2018 Sony Interactive Entertainment Inc.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    8181    : ResourceResponseBase(response.url, "", response.expectedContentLength, "")
    8282{
    83     setHTTPStatusCode(response.statusCode);
     83    setHTTPStatusCode(response.statusCode ? response.statusCode : response.httpConnectCode);
    8484
    8585    for (const auto& header : response.headers)
Note: See TracChangeset for help on using the changeset viewer.