|
1 <?php |
|
2 |
|
3 namespace CorpusParole\Http\Controllers\Proxy; |
|
4 |
|
5 use Guzzle; |
|
6 |
|
7 use Illuminate\Http\Request; |
|
8 |
|
9 use CorpusParole\Http\Requests; |
|
10 use CorpusParole\Http\Controllers\Controller; |
|
11 |
|
12 |
|
13 class BnfController extends Controller |
|
14 { |
|
15 |
|
16 const HEADERS_FORWARDED = [ "host", "user-agent", "accept", "accept-language", "accept-encoding", "connection" ]; |
|
17 |
|
18 private function proxyQuery($req, $url) { |
|
19 |
|
20 $headers = []; |
|
21 foreach (BnfController::HEADERS_FORWARDED as $h) { |
|
22 $headerValue = $req->header($h); |
|
23 if($headerValue) { |
|
24 $headers[$h] = $headerValue; |
|
25 } |
|
26 } |
|
27 |
|
28 $complResp = Guzzle::get($url, ['query' => $req->all(), 'headers' => $headers]); |
|
29 |
|
30 $resp = response((string)$complResp->getBody(), $complResp->getStatusCode()); |
|
31 foreach ($complResp->getHeaders() as $name => $values) { |
|
32 if($name != 'Transfer-Encoding') { |
|
33 $resp->header($name, $values); |
|
34 } |
|
35 } |
|
36 |
|
37 return $resp; |
|
38 |
|
39 } |
|
40 |
|
41 // proxy Auto completion query for bnf |
|
42 public function proxyAutoCompletion(Request $req) { |
|
43 return $this->proxyQuery($req, config('corpusparole.bnf_completion_url')); |
|
44 } |
|
45 |
|
46 // proxy sparql query for bnf |
|
47 public function proxySparql(Request $req) { |
|
48 |
|
49 return $this->proxyQuery($req, config('corpusparole.bnf_query_url')); |
|
50 |
|
51 } |
|
52 |
|
53 } |