Skip to content

HTTP Proxy support to access openstreetmap.org #213

@ArnaultMICHEL

Description

@ArnaultMICHEL

Hi,

I've tested your project recently : congratulations, you've done a great job!

I wish to contribute to three improvements that I consider essential for the sovereign project I am working on.

This is the first proposal, a PR will come soon.

Feature description

As we are on a private network without direct internet access, we need to configure a proxy to reach openstreetmap.org
if the proxy require authentication, we should provide the credentials

Note : the cache on the proxy should speed up the http traffic ;)

Code impact

conf/config.inc.php

I propose to store a default config that disable the proxy by default.
This can be reactivated in conf/config.inc.local.php.

# Proxy settings
$use_proxy=false;
$proxy_host = "mysquidproxy.example.com";
$proxy_port = 3128;
$proxy_use_ssl = false;
$proxy_auth = false;
$proxy_auth_user = "user";
$proxy_auth_pass = "password";

htdocs/geocode.php

as explained here, we need to add the proxy config before calling stream_context_create

$http_settings = array(
        # Set timeout to 5 seconds
        'timeout' => 5,
        'user_agent' => "LTB White-Pages address geocoding/1.0"
);
if ($use_proxy) {
    $http_settings['proxy'] = "tcp://" . $proxy_host . ":" . $proxy_port;
    if ($proxy_use_ssl) {
        $http_settings['request_fulluri'] = true;
    }
    if ($proxy_auth) {
        $http_settings['header'] = "Proxy-Authorization: Basic " . base64_encode($proxy_auth_user . ":" . $proxy_auth_pass);
    }
}

$opts = array(
    'http' => $http_settings
);

$context = stream_context_create($opts);
...

Tests

I simply install squid 6.14 on my (gentoo) VM : it's working with anonymous access.
i still need to test with authentication activated, based on this simple gist config guideline

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions