introduced http header to connection

This commit is contained in:
Jay
2026-04-30 14:09:41 -04:00
parent 6332e4438e
commit ab641e8313
6 changed files with 64 additions and 19 deletions
+12
View File
@@ -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 {