server/src/app/Http/Controllers/Proxy/BnfController.php
changeset 139 8d688175513a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/server/src/app/Http/Controllers/Proxy/BnfController.php	Fri Mar 04 19:18:28 2016 +0100
@@ -0,0 +1,53 @@
+<?php
+
+namespace CorpusParole\Http\Controllers\Proxy;
+
+use Guzzle;
+
+use Illuminate\Http\Request;
+
+use CorpusParole\Http\Requests;
+use CorpusParole\Http\Controllers\Controller;
+
+
+class BnfController extends Controller
+{
+
+    const HEADERS_FORWARDED = [ "host", "user-agent", "accept", "accept-language", "accept-encoding", "connection" ];
+
+    private function proxyQuery($req, $url) {
+
+        $headers = [];
+        foreach (BnfController::HEADERS_FORWARDED as $h) {
+            $headerValue = $req->header($h);
+            if($headerValue) {
+                $headers[$h] = $headerValue;
+            }
+        }
+
+        $complResp = Guzzle::get($url, ['query' => $req->all(), 'headers' => $headers]);
+
+        $resp = response((string)$complResp->getBody(), $complResp->getStatusCode());
+        foreach ($complResp->getHeaders() as $name => $values) {
+            if($name != 'Transfer-Encoding') {
+                $resp->header($name, $values);
+            }
+        }
+
+        return $resp;
+
+    }
+
+    // proxy Auto completion query for bnf
+    public function proxyAutoCompletion(Request $req) {
+        return $this->proxyQuery($req, config('corpusparole.bnf_completion_url'));
+    }
+
+    // proxy sparql query for bnf
+    public function proxySparql(Request $req) {
+
+        return $this->proxyQuery($req, config('corpusparole.bnf_query_url'));
+
+    }
+
+}