2019-03-11 18:56:48 +02:00
|
|
|
package api
|
2018-12-06 23:50:17 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"regexp"
|
|
|
|
)
|
|
|
|
|
|
|
|
type service struct {
|
|
|
|
core *Core
|
|
|
|
}
|
|
|
|
|
2020-05-08 19:35:25 +02:00
|
|
|
// getLink get a rel into the Link header.
|
2018-12-06 23:50:17 +02:00
|
|
|
func getLink(header http.Header, rel string) string {
|
2020-07-10 01:48:18 +02:00
|
|
|
linkExpr := regexp.MustCompile(`<(.+?)>;\s*rel="(.+?)"`)
|
2018-12-06 23:50:17 +02:00
|
|
|
|
|
|
|
for _, link := range header["Link"] {
|
|
|
|
for _, m := range linkExpr.FindAllStringSubmatch(link, -1) {
|
|
|
|
if len(m) != 3 {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
if m[2] == rel {
|
|
|
|
return m[1]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2020-05-08 19:35:25 +02:00
|
|
|
// getLocation get the value of the header Location.
|
2018-12-06 23:50:17 +02:00
|
|
|
func getLocation(resp *http.Response) string {
|
|
|
|
if resp == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp.Header.Get("Location")
|
|
|
|
}
|
|
|
|
|
2020-05-08 19:35:25 +02:00
|
|
|
// getRetryAfter get the value of the header Retry-After.
|
2018-12-06 23:50:17 +02:00
|
|
|
func getRetryAfter(resp *http.Response) string {
|
|
|
|
if resp == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
return resp.Header.Get("Retry-After")
|
|
|
|
}
|