forked from maintell/webBenchmark
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandleHttpLocation.go
More file actions
45 lines (39 loc) · 788 Bytes
/
HandleHttpLocation.go
File metadata and controls
45 lines (39 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main
import (
"fmt"
"net/http"
"time"
)
func GetHttpLocation(Url string) string {
resp, err := http.Get(Url)
if err != nil {
fmt.Println("Error:", err)
return ""
}
defer resp.Body.Close()
fmt.Println("Headers for", url)
if resp.Request == nil || resp.Request.Response == nil || resp.Request.Response.Header == nil {
return ""
}
locationHeader := resp.Request.Response.Header["Location"][0]
if len(locationHeader) > 0 {
return locationHeader
}
return ""
}
func RefreshHttpLocation(Url string) string {
defer func() {
if r := recover(); r != nil {
go RefreshHttpLocation(*url)
}
}()
for {
time.Sleep(60 * time.Second)
location := GetHttpLocation(Url)
if len(location) > 0 {
TargetUrl = location
} else {
TargetUrl = *url
}
}
}