Browse Source

Add a way to specify IP via header

Jordi Boggiano 8 years ago
parent
commit
cc6cdc3572
2 changed files with 7 additions and 1 deletions
  1. 1 0
      app/config/defaults.yml
  2. 6 1
      src/Packagist/WebBundle/Controller/ApiController.php

+ 1 - 0
app/config/defaults.yml

@@ -10,3 +10,4 @@ parameters:
     solr_port: 8983
     solr_path: /solr
     solr_core: collection1
+    trusted_ip_header: ''

+ 6 - 1
src/Packagist/WebBundle/Controller/ApiController.php

@@ -166,7 +166,12 @@ class ApiController extends Controller
         }
 
         $failed = array();
-        $ip = $request->getClientIp();
+
+        $ip = $request->headers->get('X-'.$this->container->getParameter('trusted_ip_header'));
+        if (!$ip) {
+            $ip = $request->getClientIp();
+        }
+
         $jobs = [];
         foreach ($contents['downloads'] as $package) {
             $result = $this->getPackageAndVersionId($package['name'], $package['version']);