introduced http header to connection
This commit is contained in:
@@ -2,6 +2,7 @@ package transport
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -9,6 +10,7 @@ type CloseHandler func(code int, text string) error
|
||||
|
||||
type ConnectionConfig struct {
|
||||
CloseHandler CloseHandler
|
||||
RequestHeader http.Header
|
||||
WriteTimeout time.Duration
|
||||
PingInterval time.Duration
|
||||
IncomingBufferSize int
|
||||
@@ -39,8 +41,11 @@ func NewConnectionConfig(options ...ConnectionOption) (*ConnectionConfig, error)
|
||||
}
|
||||
|
||||
func GetDefaultConnectionConfig() *ConnectionConfig {
|
||||
header := http.Header{}
|
||||
header.Set("User-Agent", "honeybee/0.1.0")
|
||||
return &ConnectionConfig{
|
||||
CloseHandler: nil,
|
||||
RequestHeader: header,
|
||||
WriteTimeout: 30 * time.Second,
|
||||
PingInterval: 20 * time.Second,
|
||||
IncomingBufferSize: 100,
|
||||
@@ -160,6 +165,13 @@ func WithCloseHandler(handler CloseHandler) ConnectionOption {
|
||||
}
|
||||
}
|
||||
|
||||
func WithRequestHeader(header http.Header) ConnectionOption {
|
||||
return func(c *ConnectionConfig) error {
|
||||
c.RequestHeader = header.Clone()
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// When WriteTimeout is set to zero, read timeouts are disabled.
|
||||
func WithWriteTimeout(value time.Duration) ConnectionOption {
|
||||
return func(c *ConnectionConfig) error {
|
||||
|
||||
Reference in New Issue
Block a user