53
53
from urllib .request import HTTPDigestAuthHandler
54
54
from urllib .request import HTTPPasswordMgrWithDefaultRealm
55
55
from urllib .request import HTTPSHandler
56
+ from urllib .request import Request
56
57
from urllib .request import build_opener
57
58
59
+ import holdup
60
+
58
61
59
62
class Check :
60
63
error = None
@@ -158,6 +161,7 @@ def __init__(self, url):
158
161
self .netloc = f"{ url .hostname } :{ url .port } "
159
162
else :
160
163
self .netloc = url .hostname
164
+ self .host = url .hostname
161
165
162
166
cleaned_url = urlunparse (url ._replace (netloc = self .netloc ))
163
167
@@ -180,8 +184,9 @@ def run(self, options):
180
184
handlers .append (HTTPSHandler (context = ssl_ctx ))
181
185
182
186
opener = build_opener (* handlers )
183
-
184
- with closing (opener .open (self .url , timeout = options .check_timeout )) as req :
187
+ opener .addheaders = [("User-Agent" , f"python-holdup/{ holdup .__version__ } " )]
188
+ request = Request (self .url , headers = {"Host" : self .host }) # noqa: S310
189
+ with closing (opener .open (request , timeout = options .check_timeout )) as req :
185
190
status = req .getcode ()
186
191
if status != 200 :
187
192
raise Exception (f"Expected status code 200, got { status !r} " )
@@ -222,6 +227,8 @@ def __init__(self, path):
222
227
self .path = path
223
228
224
229
def run (self , _ ):
230
+ # necessary to check if it exists.
231
+ os .stat (self .path ) # noqa: PTH116
225
232
if not os .access (self .path , os .R_OK ):
226
233
raise Exception (f"Failed access({ self .path !r} , R_OK) test" )
227
234
@@ -379,8 +386,6 @@ def parse_value(value, proto):
379
386
380
387
381
388
def add_version_argument (parser ):
382
- import holdup
383
-
384
389
parser .add_argument (
385
390
"--version" ,
386
391
action = "version" ,
0 commit comments