Resolve #132 - Couldn't resolve host name on handle

* By default the DNS timeout on HTTP.method is too short. If DNS
resolution takes too long, a resolution error is thrown. Increase DNS
timeout to 5 seconds.
* Cleanup unittest - double declaration
This commit is contained in:
abraunegg 2018-04-24 12:10:27 +10:00
parent dff245d29b
commit 034eccfaec
2 changed files with 13 additions and 10 deletions

View file

@ -53,6 +53,7 @@ final class OneDriveApi
{
this.cfg = cfg;
http = HTTP();
http.dnsTimeout = (dur!"seconds"(5));
if (debugHttp) {
http.verbose = true;
.debugResponse = true;

View file

@ -106,9 +106,15 @@ Regex!char wild2regex(const(char)[] pattern)
// returns true if the network connection is available
bool testNetwork()
{
HTTP http = HTTP("https://login.microsoftonline.com");
http.method = HTTP.Method.head;
return http.perform(ThrowOnError.no) == 0;
try {
HTTP http = HTTP("https://login.microsoftonline.com");
http.dnsTimeout = (dur!"seconds"(5));
http.method = HTTP.Method.head;
http.perform();
return true;
} catch (SocketException) {
return false;
}
}
// calls globMatch for each string in pattern separated by '|'
@ -122,13 +128,6 @@ bool multiGlobMatch(const(char)[] path, const(char)[] pattern)
return false;
}
unittest
{
assert(multiGlobMatch(".hidden", ".*"));
assert(multiGlobMatch(".hidden", "file|.*"));
assert(!multiGlobMatch("foo.bar", "foo|bar"));
}
bool isValidName(string path)
{
// allow root item
@ -156,6 +155,9 @@ bool isValidName(string path)
unittest
{
assert(multiGlobMatch(".hidden", ".*"));
assert(multiGlobMatch(".hidden", "file|.*"));
assert(!multiGlobMatch("foo.bar", "foo|bar"));
// that should detect invalid file/directory name.
assert(isValidName("."));
assert(isValidName("./general.file"));