summaryrefslogtreecommitdiffstats
path: root/app/post.go
diff options
context:
space:
mode:
authorTorsten Juergeleit <torsten.juergeleit@gmail.com>2017-05-31 16:34:05 +0200
committerHarrison Healey <harrisonmhealey@gmail.com>2017-05-31 10:34:05 -0400
commitfdf1164aee36d60b34ca82c07fe02b68e972f53a (patch)
treedecf173e9b6fb8d8f3c10463d065ad9234fc3391 /app/post.go
parentddc996f33fc39b2b8f4705d6e1232ccbad1ee4c7 (diff)
downloadchat-fdf1164aee36d60b34ca82c07fe02b68e972f53a.tar.gz
chat-fdf1164aee36d60b34ca82c07fe02b68e972f53a.tar.bz2
chat-fdf1164aee36d60b34ca82c07fe02b68e972f53a.zip
PLT-5705 Created a single source of http.Client creation logic with internet proxy support, reasonable timeouts and optional insecure connections (#6503)
Diffstat (limited to 'app/post.go')
-rw-r--r--app/post.go44
1 files changed, 6 insertions, 38 deletions
diff --git a/app/post.go b/app/post.go
index 341287cf4..baea6179f 100644
--- a/app/post.go
+++ b/app/post.go
@@ -4,12 +4,8 @@
package app
import (
- "net"
"net/http"
- "net/url"
- "os"
"regexp"
- "time"
l4g "github.com/alecthomas/log4go"
"github.com/dyatlov/go-opengraph/opengraph"
@@ -19,35 +15,7 @@ import (
"github.com/mattermost/platform/utils"
)
-var (
- httpClient *http.Client
-
- httpTimeout = time.Duration(5 * time.Second)
- linkWithTextRegex = regexp.MustCompile(`<([^<\|]+)\|([^>]+)>`)
-)
-
-func dialTimeout(network, addr string) (net.Conn, error) {
- return net.DialTimeout(network, addr, httpTimeout)
-}
-
-func init() {
- p, ok := os.LookupEnv("HTTP_PROXY")
- if ok {
- if u, err := url.Parse(p); err == nil {
- httpClient = &http.Client{
- Transport: &http.Transport{
- Proxy: http.ProxyURL(u),
- Dial: dialTimeout,
- },
- }
- return
- }
- }
-
- httpClient = &http.Client{
- Timeout: httpTimeout,
- }
-}
+var linkWithTextRegex = regexp.MustCompile(`<([^<\|]+)\|([^>]+)>`)
func CreatePostAsUser(post *model.Post) (*model.Post, *model.AppError) {
// Check that channel has not been deleted
@@ -126,7 +94,7 @@ func CreatePost(post *model.Post, teamId string, triggerWebhooks bool) (*model.P
}
esInterface := einterfaces.GetElasticSearchInterface()
- if (esInterface != nil && *utils.Cfg.ElasticSearchSettings.EnableIndexing) {
+ if esInterface != nil && *utils.Cfg.ElasticSearchSettings.EnableIndexing {
go esInterface.IndexPost(rpost, teamId)
}
@@ -314,7 +282,7 @@ func UpdatePost(post *model.Post, safeUpdate bool) (*model.Post, *model.AppError
rpost := result.Data.(*model.Post)
esInterface := einterfaces.GetElasticSearchInterface()
- if (esInterface != nil && *utils.Cfg.ElasticSearchSettings.EnableIndexing) {
+ if esInterface != nil && *utils.Cfg.ElasticSearchSettings.EnableIndexing {
go func() {
if rchannel := <-Srv.Store.Channel().GetForPost(rpost.Id); rchannel.Err != nil {
l4g.Error("Couldn't get channel %v for post %v for ElasticSearch indexing.", rpost.ChannelId, rpost.Id)
@@ -501,7 +469,7 @@ func DeletePost(postId string) (*model.Post, *model.AppError) {
go DeleteFlaggedPosts(post.Id)
esInterface := einterfaces.GetElasticSearchInterface()
- if (esInterface != nil && *utils.Cfg.ElasticSearchSettings.EnableIndexing) {
+ if esInterface != nil && *utils.Cfg.ElasticSearchSettings.EnableIndexing {
go esInterface.DeletePost(post.Id)
}
@@ -532,7 +500,7 @@ func SearchPostsInTeam(terms string, userId string, teamId string, isOrSearch bo
paramsList := model.ParseSearchParams(terms)
esInterface := einterfaces.GetElasticSearchInterface()
- if (esInterface != nil && *utils.Cfg.ElasticSearchSettings.EnableSearching && utils.IsLicensed && *utils.License.Features.ElasticSearch) {
+ if esInterface != nil && *utils.Cfg.ElasticSearchSettings.EnableSearching && utils.IsLicensed && *utils.License.Features.ElasticSearch {
finalParamsList := []*model.SearchParams{}
for _, params := range paramsList {
@@ -643,7 +611,7 @@ func GetFileInfosForPost(postId string, readFromMaster bool) ([]*model.FileInfo,
func GetOpenGraphMetadata(url string) *opengraph.OpenGraph {
og := opengraph.NewOpenGraph()
- res, err := httpClient.Get(url)
+ res, err := utils.HttpClient().Get(url)
if err != nil {
l4g.Error("GetOpenGraphMetadata request failed for url=%v with err=%v", url, err.Error())
return og