From 23be0167f478765eb67ba21ab8837b0cbff8705a Mon Sep 17 00:00:00 2001 From: Josta Yee Date: Wed, 1 Mar 2017 06:59:53 +0800 Subject: Set timeout to http client (#5540) Update client --- app/post.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/post.go b/app/post.go index 9ba119413..a41da6c90 100644 --- a/app/post.go +++ b/app/post.go @@ -6,6 +6,7 @@ package app import ( "net/http" "regexp" + "time" l4g "github.com/alecthomas/log4go" "github.com/dyatlov/go-opengraph/opengraph" @@ -15,6 +16,14 @@ import ( "github.com/mattermost/platform/utils" ) +var ( + c = &http.Client{ + Timeout: 5 * time.Second, + } + + linkWithTextRegex = regexp.MustCompile(`<([^<\|]+)\|([^>]+)>`) +) + func CreatePostAsUser(post *model.Post) (*model.Post, *model.AppError) { // Check that channel has not been deleted var channel *model.Channel @@ -169,8 +178,6 @@ func handlePostEvents(post *model.Post, teamId string, triggerWebhooks bool) *mo return nil } -var linkWithTextRegex *regexp.Regexp = regexp.MustCompile(`<([^<\|]+)\|([^>]+)>`) - // This method only parses and processes the attachments, // all else should be set in the post which is passed func parseSlackAttachment(post *model.Post, attachments interface{}) { @@ -497,7 +504,7 @@ func GetFileInfosForPost(postId string, readFromMaster bool) ([]*model.FileInfo, func GetOpenGraphMetadata(url string) *opengraph.OpenGraph { og := opengraph.NewOpenGraph() - res, err := http.Get(url) + res, err := c.Get(url) if err != nil { return og } -- cgit v1.2.3-1-g7c22