Rev 376 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
375 | daniel-mar | 1 | <?php |
2 | |||
3 | /* |
||
4 | * OIDplus 2.0 |
||
5 | * Copyright 2019 Daniel Marschall, ViaThinkSoft |
||
6 | * |
||
7 | * Licensed under the Apache License, Version 2.0 (the "License"); |
||
8 | * you may not use this file except in compliance with the License. |
||
9 | * You may obtain a copy of the License at |
||
10 | * |
||
11 | * http://www.apache.org/licenses/LICENSE-2.0 |
||
12 | * |
||
13 | * Unless required by applicable law or agreed to in writing, software |
||
14 | * distributed under the License is distributed on an "AS IS" BASIS, |
||
15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||
16 | * See the License for the specific language governing permissions and |
||
17 | * limitations under the License. |
||
18 | */ |
||
19 | |||
20 | // We do this stuff to avoid that the client includes an externa JavaScript from polyfill.io, |
||
21 | // since some users might have a problem with that (in regards privacy of their IP address etc.) |
||
22 | // So, the OIDplus webserver will act as proxy. |
||
23 | |||
24 | if (!isset($_SERVER['HTTP_USER_AGENT'])) die(); |
||
25 | |||
26 | $ua = $_SERVER['HTTP_USER_AGENT']; |
||
27 | |||
28 | $opts = [ |
||
29 | "http" => [ |
||
30 | "method" => "GET", |
||
31 | "header" => "User-Agent: ".$ua."\r\n" |
||
32 | ] |
||
33 | ]; |
||
34 | |||
35 | $context = stream_context_create($opts); |
||
36 | $out = file_get_contents('https://polyfill.io/v3/polyfill.min.js?features=fetch%2CURL', false, $context); |
||
37 | |||
38 | # --- |
||
39 | |||
40 | $etag = md5($out); |
||
41 | header("Etag: $etag"); |
||
42 | header('Content-MD5: '.$etag); // RFC 2616 clause 14.15 |
||
43 | if (isset($_SERVER['HTTP_IF_NONE_MATCH']) && (trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag)) { |
||
44 | header("HTTP/1.1 304 Not Modified"); |
||
45 | } else { |
||
46 | header('Content-Type:application/javascript'); |
||
47 | echo $out; |
||
48 | } |
||
49 |