MM-13838 Bypass the HTTP client when getting image dimensions from the image proxy (#10208)
* MM-13838 Bypass the HTTP client when getting image dimensions from the proxy * Add additional log messages to debug failing test * Fix unit test to work on Jenkins
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
85c60f1402
Коммит
dbf54b3599
@@ -346,18 +346,34 @@ func (a *App) getLinkMetadata(requestURL string, timestamp int64, isNewPost bool
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
request.Header.Add("Accept", "text/html, image/*")
|
||||
var body io.ReadCloser
|
||||
var contentType string
|
||||
|
||||
client := a.HTTPService.MakeClient(false)
|
||||
client.Timeout = time.Duration(*a.Config().ExperimentalSettings.LinkMetadataTimeoutMilliseconds) * time.Millisecond
|
||||
if (request.URL.Scheme+"://"+request.URL.Host) == a.GetSiteURL() && request.URL.Path == "/api/v4/image" {
|
||||
// /api/v4/image requires authentication, so bypass the API by hitting the proxy directly
|
||||
body, contentType, err = a.ImageProxy.GetImageDirect(a.ImageProxy.GetUnproxiedImageURL(request.URL.String()))
|
||||
} else {
|
||||
request.Header.Add("Accept", "text/html, image/*")
|
||||
|
||||
res, err := client.Do(request)
|
||||
client := a.HTTPService.MakeClient(false)
|
||||
client.Timeout = time.Duration(*a.Config().ExperimentalSettings.LinkMetadataTimeoutMilliseconds) * time.Millisecond
|
||||
|
||||
var res *http.Response
|
||||
res, err = client.Do(request)
|
||||
|
||||
if res != nil {
|
||||
body = res.Body
|
||||
contentType = res.Header.Get("Content-Type")
|
||||
}
|
||||
}
|
||||
|
||||
if body != nil {
|
||||
defer body.Close()
|
||||
}
|
||||
|
||||
if err == nil {
|
||||
defer res.Body.Close()
|
||||
|
||||
// Parse the data
|
||||
og, image, err = a.parseLinkMetadata(requestURL, res.Body, res.Header.Get("Content-Type"))
|
||||
og, image, err = a.parseLinkMetadata(requestURL, body, contentType)
|
||||
}
|
||||
|
||||
// Write back to cache and database, even if there was an error and the results are nil
|
||||
|
||||
Ссылка в новой задаче
Block a user