summaryrefslogtreecommitdiffstats
path: root/model
diff options
context:
space:
mode:
authorMartin Kraft <martinkraft@gmail.com>2018-08-24 08:49:31 -0400
committerGitHub <noreply@github.com>2018-08-24 08:49:31 -0400
commited0fb617ef629a39d27441336951c098b13324d0 (patch)
tree447c0b1053a937fceb942f286fdc4036db36f91b /model
parentf9dbea6d860a71d8756d69b80a5fc0fe91d6514b (diff)
downloadchat-ed0fb617ef629a39d27441336951c098b13324d0.tar.gz
chat-ed0fb617ef629a39d27441336951c098b13324d0.tar.bz2
chat-ed0fb617ef629a39d27441336951c098b13324d0.zip
MM-11786: Adds API endpoint to retrieve redirect locations. (#9284)
Diffstat (limited to 'model')
-rw-r--r--model/client4.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/model/client4.go b/model/client4.go
index 48627c4b0..4f651b976 100644
--- a/model/client4.go
+++ b/model/client4.go
@@ -397,6 +397,10 @@ func (c *Client4) GetTotalUsersStatsRoute() string {
return fmt.Sprintf(c.GetUsersRoute() + "/stats")
}
+func (c *Client4) GetRedirectLocationRoute() string {
+ return fmt.Sprintf("/redirect_location")
+}
+
func (c *Client4) DoApiGet(url string, etag string) (*http.Response, *AppError) {
return c.DoApiRequest(http.MethodGet, c.ApiUrl+url, "", etag)
}
@@ -3771,3 +3775,14 @@ func (c *Client4) UpdateTeamScheme(teamId, schemeId string) (bool, *Response) {
return CheckStatusOK(r), BuildResponse(r)
}
}
+
+// GetRedirectLocation retrieves the value of the 'Location' header of an HTTP response for a given URL.
+func (c *Client4) GetRedirectLocation(urlParam, etag string) (string, *Response) {
+ url := fmt.Sprintf("%s?url=%s", c.GetRedirectLocationRoute(), url.QueryEscape(urlParam))
+ if r, err := c.DoApiGet(url, etag); err != nil {
+ return "", BuildErrorResponse(r, err)
+ } else {
+ defer closeBody(r)
+ return MapFromJson(r.Body)["location"], BuildResponse(r)
+ }
+}