snapshot of https://github.com/centrifugal/centrifugo.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
test / Lint (push) Failing after 3s
test / Test with Go 1.26.8 (push) Failing after 2s

This commit is contained in:
upstream-mirror
2026-09-16 01:17:21 +05:00
commit b352a9a30d
472 changed files with 108375 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
package proxy
import (
"context"
"encoding/json"
"fmt"
"github.com/centrifugal/centrifugo/v6/internal/proxyproto"
)
// PublishRequestHTTP ...
type PublishRequestHTTP struct {
baseRequestHTTP
UserID string `json:"user"`
Channel string `json:"channel"`
Data json.RawMessage `json:"data,omitempty"`
// Base64Data to proxy binary data.
Base64Data string `json:"b64data,omitempty"`
}
// HTTPPublishProxy ...
type HTTPPublishProxy struct {
config Config
httpCaller HTTPCaller
}
var _ PublishProxy = (*HTTPPublishProxy)(nil)
// NewHTTPPublishProxy ...
func NewHTTPPublishProxy(p Config) (*HTTPPublishProxy, error) {
httpClient, err := proxyHTTPClient(p, "publish_proxy")
if err != nil {
return nil, fmt.Errorf("error creating HTTP client: %w", err)
}
return &HTTPPublishProxy{
httpCaller: NewHTTPCaller(httpClient),
config: p,
}, nil
}
// ProxyPublish proxies Publish to application backend.
func (p *HTTPPublishProxy) ProxyPublish(ctx context.Context, req *proxyproto.PublishRequest) (*proxyproto.PublishResponse, error) {
data, err := httpEncoder.EncodePublishRequest(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 transformPublishResponse(err, p.config.HTTP.StatusToCodeTransforms)
}
return httpDecoder.DecodePublishResponse(respData)
}
// Protocol ...
func (p *HTTPPublishProxy) Protocol() string {
return "http"
}
// UseBase64 ...
func (p *HTTPPublishProxy) UseBase64() bool {
return p.config.BinaryEncoding
}
// IncludeMeta ...
func (p *HTTPPublishProxy) IncludeMeta() bool {
return p.config.IncludeConnectionMeta
}