Change timeout to 5s, then assume offline
This commit is contained in:
parent
7927b515f2
commit
04ab5e3002
@ -16,9 +16,13 @@ func routes(_ app: Application) throws {
|
|||||||
|
|
||||||
app.get("status", ":url") { req -> [String: String] in
|
app.get("status", ":url") { req -> [String: String] in
|
||||||
let url = URL(string: "http://\(req.parameters.get("url")!)")
|
let url = URL(string: "http://\(req.parameters.get("url")!)")
|
||||||
|
let config = URLSessionConfiguration.default
|
||||||
|
config.timeoutIntervalForRequest = 5
|
||||||
|
config.timeoutIntervalForResource = 5
|
||||||
var statusDict: [String:String] = [:]
|
var statusDict: [String:String] = [:]
|
||||||
var headReq = URLRequest(url: url!)
|
var headReq = URLRequest(url: url!)
|
||||||
headReq.httpMethod = "HEAD"
|
headReq.httpMethod = "HEAD"
|
||||||
|
headReq.timeoutInterval = 5
|
||||||
let semaphore = DispatchSemaphore(value: 0)
|
let semaphore = DispatchSemaphore(value: 0)
|
||||||
URLSession.shared.dataTask(with: headReq, completionHandler: { (_, response, error) in
|
URLSession.shared.dataTask(with: headReq, completionHandler: { (_, response, error) in
|
||||||
if let httpURLResponse = response as? HTTPURLResponse {
|
if let httpURLResponse = response as? HTTPURLResponse {
|
||||||
|
Reference in New Issue
Block a user