Skip to content

Commit 138db76

Browse files
committed
Simplified proxy configuration
1 parent bcc0682 commit 138db76

File tree

5 files changed

+22
-27
lines changed

5 files changed

+22
-27
lines changed

Readme.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,14 @@ Then in `schema.json`, specify the function's name in the *pattern* field of you
102102

103103
## Running behind a proxy
104104

105-
Add a file called *proxy.php* to the config directory with a function called `file_get_contents_with_proxy`. This function should accept a URL as an argument, and return the HTML of the specified URL.
105+
Add a file called *proxy.php* to the config directory. Within the file, use [`stream_context_set_default`](http://php.net/manual/en/function.stream-context-set-default.php) to configure the proxy.
106106

107107
## Changelog
108108

109+
### 2.0.0
110+
111+
- Simplified proxy configuration
112+
109113
### 1.0.1
110114

111115
- New content types: 'url' and 'strict-url'

api/scraper.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
include '../config/proxy.php';
1111
}
1212

13-
1413
function checkUrl( $url ) {
1514

1615
if ( file_exists('../config/custom.php') ) {
@@ -21,11 +20,7 @@ function checkUrl( $url ) {
2120
return false;
2221
}
2322

24-
if (function_exists('file_get_contents_with_proxy')) {
25-
$file = file_get_contents_with_proxy( $url );
26-
} else {
27-
$file = file_get_contents( $url );
28-
}
23+
$file = file_get_contents( $url );
2924

3025
if (!$file) {
3126
return false;
@@ -105,15 +100,13 @@ function checkUrl( $url ) {
105100
$strict = true;
106101
}
107102
$item_url = $schema[$i]['contents'];
108-
if (function_exists('file_get_contents_with_proxy')) {
109-
file_get_contents_with_proxy( $item_url );
110-
} else {
103+
if (!empty($item_url)) {
111104
file_get_contents( $item_url );
112-
}
113-
$headerStatus = checkHeaderStatus($http_response_header, $strict);
114-
$schema[$i]['_requestHeader'] = $http_response_header;
115-
if ( !is_null($http_response_header) && ($headerStatus === false) ) {
116-
$schema[$i]['ok'] = false;
105+
$headerStatus = checkHeaderStatus($http_response_header, $strict);
106+
$schema[$i]['_requestHeader'] = $http_response_header;
107+
if ( !is_null($http_response_header) && ($headerStatus === false) ) {
108+
$schema[$i]['ok'] = false;
109+
}
117110
}
118111
}
119112

config_examples/HOW TO CONFIGURE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ Used to specify custom selectors and validators. See Readme for more info.
1212

1313
## proxy.php
1414

15-
Add a file called *proxy.php* to the config directory with a function called `file_get_contents_with_proxy`. This function should accept a URL as an argument, and return the HTML of the specified URL.
15+
Add a file called *proxy.php* to the config directory. Within the file, use [`stream_context_set_default`](http://php.net/manual/en/function.stream-context-set-default.php) to configure the proxy.

config_examples/proxy.example.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,13 @@
44
This is an example of how one might use the meta checker with a proxy.
55
*/
66

7-
if (file_exists('../my/internal/proxy.php')) {
8-
include_once('../my/internal/proxy.php');
9-
function file_get_contents_with_proxy($url) {
10-
return myInternalProxy($url);
11-
}
12-
} else {
13-
function file_get_contents_with_proxy($url){
14-
return file_get_contents($url);
15-
}
16-
}
7+
stream_context_set_default(
8+
array(
9+
'http' => array(
10+
'proxy' => "tcp://proxy.mycompany.net:80",
11+
'request_fulluri' => true,
12+
)
13+
)
14+
);
1715

1816
?>

index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ <h3>{{group}}</h3>
5454

5555
</div>
5656

57-
<p class="footer"><a target="_self" ng-href="./api/index.php?url={{currentUrl}}">API version of this check</a> | The Meta Tag Checker. v1.0.1 | <a href="https://github.com/dowjones/the-meta-tag-checker">View source on Github</a></p>
57+
<p class="footer"><a target="_self" ng-href="./api/index.php?url={{currentUrl}}">API version of this check</a> | The Meta Tag Checker. v2.0.0 | <a href="https://github.com/dowjones/the-meta-tag-checker">View source on Github</a></p>
5858

5959

6060

0 commit comments

Comments
 (0)