mirror of
https://github.com/hoernschen/dendrite.git
synced 2025-07-29 12:42:46 +00:00
use custom http client instead of the http DefaultClient (#823)
This commit replaces the default client from the http lib with a custom one. The previously used default client doesn't come with a timeout. This could cause unwanted locks. That solution chosen here creates a http client in the base component dendrite with a constant timeout of 30 seconds. If it should be necessary to overwrite this, we could include the timeout in the dendrite configuration. Here it would be a good idea to extend the type "Address" by a timeout and create an http client for each service. Closes #820 Signed-off-by: Benedikt Bongartz <benne@klimlive.de> Co-authored-by: Kegsay <kegan@matrix.org>
This commit is contained in:
parent
2c8950221e
commit
955244c092
8 changed files with 77 additions and 32 deletions
|
@ -2,6 +2,7 @@ package api
|
|||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
|
||||
commonHTTP "github.com/matrix-org/dendrite/common/http"
|
||||
|
@ -58,12 +59,12 @@ const FederationSenderQueryJoinedHostsInRoomPath = "/api/federationsender/queryJ
|
|||
const FederationSenderQueryJoinedHostServerNamesInRoomPath = "/api/federationsender/queryJoinedHostServerNamesInRoom"
|
||||
|
||||
// NewFederationSenderQueryAPIHTTP creates a FederationSenderQueryAPI implemented by talking to a HTTP POST API.
|
||||
// If httpClient is nil then it uses the http.DefaultClient
|
||||
func NewFederationSenderQueryAPIHTTP(federationSenderURL string, httpClient *http.Client) FederationSenderQueryAPI {
|
||||
// If httpClient is nil an error is returned
|
||||
func NewFederationSenderQueryAPIHTTP(federationSenderURL string, httpClient *http.Client) (FederationSenderQueryAPI, error) {
|
||||
if httpClient == nil {
|
||||
httpClient = http.DefaultClient
|
||||
return nil, errors.New("NewFederationSenderQueryAPIHTTP: httpClient is <nil>")
|
||||
}
|
||||
return &httpFederationSenderQueryAPI{federationSenderURL, httpClient}
|
||||
return &httpFederationSenderQueryAPI{federationSenderURL, httpClient}, nil
|
||||
}
|
||||
|
||||
type httpFederationSenderQueryAPI struct {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue