Change timeout to 5s, then assume offline

This commit is contained in:
Elara 2020-11-15 11:36:10 -08:00
parent 7927b515f2
commit 04ab5e3002
1 changed files with 4 additions and 0 deletions

View File

@ -16,9 +16,13 @@ func routes(_ app: Application) throws {
app.get("status", ":url") { req -> [String: String] in
let url = URL(string: "http://\(req.parameters.get("url")!)")
let config = URLSessionConfiguration.default
config.timeoutIntervalForRequest = 5
config.timeoutIntervalForResource = 5
var statusDict: [String:String] = [:]
var headReq = URLRequest(url: url!)
headReq.httpMethod = "HEAD"
headReq.timeoutInterval = 5
let semaphore = DispatchSemaphore(value: 0)
URLSession.shared.dataTask(with: headReq, completionHandler: { (_, response, error) in
if let httpURLResponse = response as? HTTPURLResponse {