Skip to content

Commit 9b88db0

Browse files
committed
Add a separate proxy configuration option for Bridge -> HS
1 parent d3c7c3f commit 9b88db0

File tree

5 files changed

+16
-0
lines changed

5 files changed

+16
-0
lines changed

example-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ appservice:
7171

7272
# Bridge config
7373
bridge:
74+
# Proxy for homeserver connection.
75+
hs_proxy:
7476
# Localpart template of MXIDs for WeChat users.
7577
username_template: _wechat_{{.}}
7678
# Displayname template for WeChat users.

internal/config/bridgeconfig.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ const (
1818
)
1919

2020
type BridgeConfig struct {
21+
HomeserverProxy string `yaml:"hs_proxy"`
22+
2123
UsernameTemplate string `yaml:"username_template"`
2224
DisplaynameTemplate string `yaml:"displayname_template"`
2325
ListenAddress string `yaml:"listen_address"`

internal/config/upgrade.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
func DoUpgrade(helper *up.Helper) {
1010
bridgeconfig.Upgrader.DoUpgrade(helper)
1111

12+
helper.Copy(up.Str, "bridge", "hs_proxy")
1213
helper.Copy(up.Str, "bridge", "username_template")
1314
helper.Copy(up.Str, "bridge", "displayname_template")
1415
helper.Copy(up.Str, "bridge", "listen_address")

internal/wechat/service.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ func (ws *WechatService) getConn(client *WechatClient) *Conn {
265265
if conn, ok := ws.conns[client.getConnKey()]; ok {
266266
return conn
267267
} else {
268+
// a better connection pick?
268269
for k, v := range ws.conns {
269270
client.setConnKey(k)
270271
return v

internal/wechatbridge.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"context"
55
"errors"
66
"fmt"
7+
"net/http"
8+
"net/url"
79
"os"
810
"sync"
911
"time"
@@ -101,6 +103,14 @@ func (br *WechatBridge) Init() {
101103
)
102104

103105
br.WebsocketHandler = NewWebsocketCommandHandler(br)
106+
107+
if br.Config.Bridge.HomeserverProxy != "" {
108+
if proxyUrl, err := url.Parse(br.Config.Bridge.HomeserverProxy); err != nil {
109+
br.Log.Warnfln("Failed to parse bridge.hs_proxy: %v", err)
110+
} else {
111+
br.AS.HTTPClient.Transport = &http.Transport{Proxy: http.ProxyURL(proxyUrl)}
112+
}
113+
}
104114
}
105115

106116
func (br *WechatBridge) Start() {

0 commit comments

Comments
 (0)