snapshot of https://github.com/centrifugal/centrifugo.git (master, 2026-09-16; blobs > 131072B omitted)
This commit is contained in:
61
internal/proxy/refresh_http.go
Normal file
61
internal/proxy/refresh_http.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"github.com/centrifugal/centrifugo/v6/internal/proxyproto"
|
||||
)
|
||||
|
||||
// HTTPRefreshProxy ...
|
||||
type HTTPRefreshProxy struct {
|
||||
config Config
|
||||
httpCaller HTTPCaller
|
||||
}
|
||||
|
||||
var _ RefreshProxy = (*HTTPRefreshProxy)(nil)
|
||||
|
||||
// NewHTTPRefreshProxy ...
|
||||
func NewHTTPRefreshProxy(p Config) (*HTTPRefreshProxy, error) {
|
||||
httpClient, err := proxyHTTPClient(p, "refresh_proxy")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error creating HTTP client: %w", err)
|
||||
}
|
||||
return &HTTPRefreshProxy{
|
||||
config: p,
|
||||
httpCaller: NewHTTPCaller(httpClient),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// ProxyRefresh proxies refresh to application backend.
|
||||
func (p *HTTPRefreshProxy) ProxyRefresh(ctx context.Context, req *proxyproto.RefreshRequest) (*proxyproto.RefreshResponse, error) {
|
||||
data, err := httpEncoder.EncodeRefreshRequest(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
respData, err := p.httpCaller.CallHTTP(ctx, p.config.Endpoint, httpRequestHeaders(ctx, p.config), data)
|
||||
if err != nil {
|
||||
return transformRefreshResponse(err, p.config.HTTP.StatusToCodeTransforms)
|
||||
}
|
||||
return httpDecoder.DecodeRefreshResponse(respData)
|
||||
}
|
||||
|
||||
// Name ...
|
||||
func (p *HTTPRefreshProxy) Name() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
// Protocol ...
|
||||
func (p *HTTPRefreshProxy) Protocol() string {
|
||||
return "http"
|
||||
}
|
||||
|
||||
// UseBase64 ...
|
||||
func (p *HTTPRefreshProxy) UseBase64() bool {
|
||||
return p.config.BinaryEncoding
|
||||
}
|
||||
|
||||
// IncludeMeta ...
|
||||
func (p *HTTPRefreshProxy) IncludeMeta() bool {
|
||||
return p.config.IncludeConnectionMeta
|
||||
}
|
||||
Reference in New Issue
Block a user