Skip to content
Snippets Groups Projects
Commit 91f781f8 authored by rswindell's avatar rswindell
Browse files

Actually check the http response code.

If the URL requested is not a filename, use a fake file (wget-output).
Don't wipe-out a local file with the same name if the HTTP-GET fails.
parent 60a3ba1b
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,9 @@ if (argv[1]) {
var purl = new URL(url);
if(!file_getname(filename))
filename += "wget-output";
print("Writing to file: " + filename);
var file = new File(filename);
......@@ -33,14 +36,27 @@ switch(purl.scheme) {
break;
case 'http':
case 'https':
if(!file.open("w"))
print("error " + file.error + " opening " + file.name);
{
var http_request = new HTTPRequest();
var contents = "";
try {
contents = http_request.Get(url);
} catch(e) {
alert(e);
break;
}
if(http_request.response_code != http_request.status.ok)
alert("HTTP-GET ERROR " + http_request.response_code);
else {
var contents = new HTTPRequest().Get(url);
file.write(contents);
file.close();
if(!file.open("w"))
print("error " + file.error + " opening " + file.name);
else {
file.write(contents);
file.close();
}
}
break;
}
default:
print("Unhandled URL scheme '"+purl.scheme+"'");
print("Unsupported URL scheme '"+purl.scheme+"'");
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment