@@ -20,6 +20,7 @@ var pkg = require("../package.json");
20
20
program . version ( pkg . version )
21
21
. usage ( "[options] <url>" )
22
22
. option ( "-l, --log" , "log errors in a text file" )
23
+ . option ( "-m, --max <n>" , "max URLs to crawl" )
23
24
. option ( "-q, --query" , "consider query string" )
24
25
. option ( "-v, --verbose" , "show error details" )
25
26
. parse ( process . argv ) ;
@@ -35,6 +36,7 @@ var W3CValidator = function(url, java_home) {
35
36
this . invalid = 0 ;
36
37
this . JAVA_HOME = java_home ;
37
38
this . logData = "" ;
39
+ this . httpProxy = false ;
38
40
39
41
this . uri = new URL ( url ) ;
40
42
this . crawler = new Crawler ( this . uri . host ) ;
@@ -54,6 +56,22 @@ var W3CValidator = function(url, java_home) {
54
56
this . uri . set ( "protocol" , "http:" ) ;
55
57
}
56
58
59
+ // Get proxy
60
+ if ( [ "127.0.0.1" , "localhost" ] . indexOf ( this . crawler . host ) === - 1 ) {
61
+ if ( process . env . HTTP_PROXY !== undefined ) {
62
+ this . httpProxy = URL ( process . env . HTTP_PROXY ) ;
63
+ } else if ( process . env . http_proxy !== undefined ) {
64
+ this . httpProxy = URL ( process . env . http_proxy ) ;
65
+ }
66
+ }
67
+
68
+ // Set Crawler proxy
69
+ if ( this . httpProxy !== false ) {
70
+ this . crawler . useProxy = true ;
71
+ this . crawler . proxyHostname = this . httpProxy . hostname ;
72
+ this . crawler . proxyPort = this . httpProxy . port ;
73
+ }
74
+
57
75
this . crawler . initialProtocol = this . uri . protocol . replace ( ":" , "" ) ;
58
76
this . crawler . userAgent = "Node/W3CValidator" ;
59
77
@@ -75,12 +93,20 @@ var W3CValidator = function(url, java_home) {
75
93
76
94
W3CValidator . prototype . checkURL = function ( ) {
77
95
var url = this . chunk . pop ( ) ;
96
+ var javaOpts = ""
97
+
98
+ // Set JAVA Proxy
99
+ if ( this . httpProxy !== false ) {
100
+ javaOpts += `-Dhttp.proxyHost=${ this . httpProxy . hostname } -Dhttp.proxyPort=${ this . httpProxy . port } `
101
+ }
78
102
79
103
var spinner = new Spinner ( ` ${ url } %s` ) ;
80
104
spinner . start ( ) ;
81
105
106
+
107
+
82
108
var vnuPath = path . join ( __dirname , "../vnu/vnu.jar" ) . replace ( / \s / g, "\\ " ) ;
83
- var child = exec ( `java -jar ${ vnuPath } --format json ${ url } ` , { env : { JAVA_HOME : this . JAVA_HOME } } , ( error , stdout , stderr ) => {
109
+ var child = exec ( `java ${ javaOpts } -jar ${ vnuPath } --format json ${ url } ` , { env : { JAVA_HOME : this . JAVA_HOME } } , ( error , stdout , stderr ) => {
84
110
var errors = JSON . parse ( stderr ) ;
85
111
86
112
spinner . stop ( true ) ;
@@ -135,6 +161,10 @@ W3CValidator.prototype.create = function() {
135
161
136
162
this . crawler . on ( "fetchcomplete" , ( item ) => {
137
163
this . chunk . push ( item . url ) ;
164
+ if ( program . max && this . chunk . length >= program . max ) {
165
+ this . crawler . emit ( "complete" ) ;
166
+ this . crawler . stop ( ) ;
167
+ }
138
168
} ) ;
139
169
140
170
this . crawler . on ( "complete" , ( ) => {
0 commit comments