aboutsummaryrefslogtreecommitdiff
path: root/roomserver
diff options
context:
space:
mode:
authorBen B <benne@klimlive.de>2020-04-03 12:40:50 +0200
committerGitHub <noreply@github.com>2020-04-03 11:40:50 +0100
commit955244c09298d0e6c870377dad3af2ffa1f5e578 (patch)
tree746c74e6efdae1eec0f06930b07bf0a23dfc55f7 /roomserver
parent2c8950221ef47cf4298dbd1f6e94450e4c35a81e (diff)
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>
Diffstat (limited to 'roomserver')
-rw-r--r--roomserver/api/alias.go9
-rw-r--r--roomserver/api/input.go9
-rw-r--r--roomserver/api/query.go9
3 files changed, 15 insertions, 12 deletions
diff --git a/roomserver/api/alias.go b/roomserver/api/alias.go
index cb78f726..ad375a83 100644
--- a/roomserver/api/alias.go
+++ b/roomserver/api/alias.go
@@ -16,6 +16,7 @@ package api
import (
"context"
+ "errors"
"net/http"
commonHTTP "github.com/matrix-org/dendrite/common/http"
@@ -139,12 +140,12 @@ const RoomserverGetCreatorIDForAliasPath = "/api/roomserver/GetCreatorIDForAlias
const RoomserverRemoveRoomAliasPath = "/api/roomserver/removeRoomAlias"
// NewRoomserverAliasAPIHTTP creates a RoomserverAliasAPI implemented by talking to a HTTP POST API.
-// If httpClient is nil then it uses the http.DefaultClient
-func NewRoomserverAliasAPIHTTP(roomserverURL string, httpClient *http.Client) RoomserverAliasAPI {
+// If httpClient is nil an error is returned
+func NewRoomserverAliasAPIHTTP(roomserverURL string, httpClient *http.Client) (RoomserverAliasAPI, error) {
if httpClient == nil {
- httpClient = http.DefaultClient
+ return nil, errors.New("NewRoomserverAliasAPIHTTP: httpClient is <nil>")
}
- return &httpRoomserverAliasAPI{roomserverURL, httpClient}
+ return &httpRoomserverAliasAPI{roomserverURL, httpClient}, nil
}
type httpRoomserverAliasAPI struct {
diff --git a/roomserver/api/input.go b/roomserver/api/input.go
index f07cc022..42e8385d 100644
--- a/roomserver/api/input.go
+++ b/roomserver/api/input.go
@@ -17,6 +17,7 @@ package api
import (
"context"
+ "errors"
"net/http"
commonHTTP "github.com/matrix-org/dendrite/common/http"
@@ -112,12 +113,12 @@ type RoomserverInputAPI interface {
const RoomserverInputRoomEventsPath = "/api/roomserver/inputRoomEvents"
// NewRoomserverInputAPIHTTP creates a RoomserverInputAPI implemented by talking to a HTTP POST API.
-// If httpClient is nil then it uses the http.DefaultClient
-func NewRoomserverInputAPIHTTP(roomserverURL string, httpClient *http.Client) RoomserverInputAPI {
+// If httpClient is nil an error is returned
+func NewRoomserverInputAPIHTTP(roomserverURL string, httpClient *http.Client) (RoomserverInputAPI, error) {
if httpClient == nil {
- httpClient = http.DefaultClient
+ return nil, errors.New("NewRoomserverInputAPIHTTP: httpClient is <nil>")
}
- return &httpRoomserverInputAPI{roomserverURL, httpClient}
+ return &httpRoomserverInputAPI{roomserverURL, httpClient}, nil
}
type httpRoomserverInputAPI struct {
diff --git a/roomserver/api/query.go b/roomserver/api/query.go
index 3cb1b8a7..9120da4b 100644
--- a/roomserver/api/query.go
+++ b/roomserver/api/query.go
@@ -18,6 +18,7 @@ package api
import (
"context"
+ "errors"
"net/http"
commonHTTP "github.com/matrix-org/dendrite/common/http"
@@ -406,12 +407,12 @@ const RoomserverQueryRoomVersionCapabilitiesPath = "/api/roomserver/queryRoomVer
const RoomserverQueryRoomVersionForRoomPath = "/api/roomserver/queryRoomVersionForRoom"
// NewRoomserverQueryAPIHTTP creates a RoomserverQueryAPI implemented by talking to a HTTP POST API.
-// If httpClient is nil then it uses the http.DefaultClient
-func NewRoomserverQueryAPIHTTP(roomserverURL string, httpClient *http.Client) RoomserverQueryAPI {
+// If httpClient is nil an error is returned
+func NewRoomserverQueryAPIHTTP(roomserverURL string, httpClient *http.Client) (RoomserverQueryAPI, error) {
if httpClient == nil {
- httpClient = http.DefaultClient
+ return nil, errors.New("NewRoomserverQueryAPIHTTP: httpClient is <nil>")
}
- return &httpRoomserverQueryAPI{roomserverURL, httpClient}
+ return &httpRoomserverQueryAPI{roomserverURL, httpClient}, nil
}
type httpRoomserverQueryAPI struct {