Documentation
¶
Index ¶
- Constants
- Variables
- func RunParserTest(t *testing.T, tc ParserTestCase)
- func RunParserTestTable(t *testing.T, cases []ParserTestCase)
- type BodyCallback
- type Callbacks
- type ChunkedDataSender
- type ErrorCallback
- type Event
- type EventCollector
- type EventType
- type HTTPStream
- type HTTPStreamOpt
- type Parser
- type ParserTestCase
- type Phase
- type Request
- type Response
- type Session
- func (s *Session) Close() error
- func (s *Session) Closed() bool
- func (s *Session) OnDone()
- func (s *Session) OnError(err error)
- func (s *Session) OnInterimResponse(resp *Response)
- func (s *Session) OnRequest(req *Request, noBody bool)
- func (s *Session) OnRequestBody(chunk []byte, isComplete bool)
- func (s *Session) OnResponse(resp *Response, noBody bool)
- func (s *Session) OnResponseBody(chunk []byte, isComplete bool)
- func (s *Session) Write(phase Phase, data []byte) error
- type TestCallbackOption
- type TestCallbackRecorder
- func (r *TestCallbackRecorder) CollectEvents(stopOnDone bool) []Event
- func (r *TestCallbackRecorder) GetState() TestState
- func (r *TestCallbackRecorder) OnDone()
- func (r *TestCallbackRecorder) OnError(err error)
- func (r *TestCallbackRecorder) OnInterimResponse(resp *Response)
- func (r *TestCallbackRecorder) OnRequest(req *Request, noBody bool)
- func (r *TestCallbackRecorder) OnRequestBody(data []byte, complete bool)
- func (r *TestCallbackRecorder) OnResponse(resp *Response, noBody bool)
- func (r *TestCallbackRecorder) OnResponseBody(data []byte, complete bool)
- func (r *TestCallbackRecorder) WaitForCompletion() error
- func (r *TestCallbackRecorder) WaitForEvent(eventType EventType) (*Event, error)
- func (r *TestCallbackRecorder) WaitForEvents(eventTypes ...EventType) ([]*Event, error)
- func (r *TestCallbackRecorder) WaitForEventsFlexible(timeout time.Duration, eventTypes ...EventType) ([]*Event, error)
- type TestState
- type TransactionState
Constants ¶
const MaxHeaderSize = 32 << 10 // 32 KiB
MaxHeaderSize is the maximum size of a header in bytes
Variables ¶
var (
ErrIncompleteHeader = errors.New("incomplete header")
)
Functions ¶
func RunParserTest ¶
func RunParserTest(t *testing.T, tc ParserTestCase)
RunParserTest runs a single parser test case
func RunParserTestTable ¶
func RunParserTestTable(t *testing.T, cases []ParserTestCase)
RunParserTestTable runs a table of parser test cases
Types ¶
type BodyCallback ¶
BodyCallback is a function type for handling body data
type Callbacks ¶
type Callbacks interface {
OnRequest(*Request, bool) // request, noBody
OnRequestBody([]byte, bool) // chunk data, isComplete
OnInterimResponse(*Response)
OnResponse(*Response, bool) // response, noBody
OnResponseBody([]byte, bool) // chunk data, isComplete
OnError(error)
OnDone() // called when transaction is complete
}
Callbacks interface for parsed HTTP messages
type ChunkedDataSender ¶
type ChunkedDataSender struct {
// contains filtered or unexported fields
}
ChunkedDataSender helps test partial data transmission scenarios
func NewChunkedDataSender ¶
func NewChunkedDataSender(t *testing.T, parser *Parser) *ChunkedDataSender
NewChunkedDataSender creates a helper for sending data in chunks
func (*ChunkedDataSender) SendByLines ¶
SendByLines sends data line by line with optional delay
func (*ChunkedDataSender) SendInChunks ¶
func (c *ChunkedDataSender) SendInChunks(phase Phase, data []byte, chunkSize int, delay time.Duration) error
SendInChunks sends data in specified chunk sizes with optional delay
type ErrorCallback ¶
type ErrorCallback func(error)
ErrorCallback is a function type for reporting errors
type Event ¶
type Event struct {
Type EventType
Request *Request
Response *Response
Body []byte
Complete bool
NoBody bool
Error error
}
Event represents a callback event for testing
type EventCollector ¶
type EventCollector struct {
// contains filtered or unexported fields
}
EventCollector helps collect and analyze events
func NewEventCollector ¶
func NewEventCollector(t *testing.T, recorder *TestCallbackRecorder) *EventCollector
NewEventCollector creates a new event collector
func (*EventCollector) AssertEventSequence ¶
func (c *EventCollector) AssertEventSequence(expected []EventType)
AssertEventSequence verifies events occurred in expected order
func (*EventCollector) CollectFor ¶
func (c *EventCollector) CollectFor(duration time.Duration)
CollectFor collects events for a specified duration
func (*EventCollector) GetEventsByType ¶
func (c *EventCollector) GetEventsByType(eventType EventType) []Event
GetEventsByType returns all events of a specific type
func (*EventCollector) WaitForEventType ¶
func (c *EventCollector) WaitForEventType(eventType EventType, timeout time.Duration) ([]Event, bool)
WaitForEventType waits for a specific event type and returns all collected events
type HTTPStream ¶
type HTTPStream struct {
// contains filtered or unexported fields
}
HTTPStream manages the read/write & open/close events for an http req/res connection stream based on socket events.
func NewHTTPStream ¶
func NewHTTPStream(ctx context.Context, domain string, logger *zap.Logger, conn *connection.Connection, opts ...HTTPStreamOpt) *HTTPStream
func (*HTTPStream) Close ¶
func (t *HTTPStream) Close()
func (*HTTPStream) Closed ¶
func (t *HTTPStream) Closed() bool
func (*HTTPStream) Process ¶
func (t *HTTPStream) Process(event *connection.DataEvent) error
type HTTPStreamOpt ¶
type HTTPStreamOpt func(*HTTPStream)
func SetPluginManager ¶
func SetPluginManager(manager *plugins.Manager) HTTPStreamOpt
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser handles a single HTTP/1.1 transaction
func (*Parser) IsComplete ¶
IsComplete returns true if the transaction is complete
func (*Parser) ProcessEvent ¶
ProcessEvent handles incoming data events by writing them to the appropriate pipe
func (*Parser) WaitForCompletion ¶
WaitForCompletion blocks until the transaction is complete or context is cancelled
type ParserTestCase ¶
type ParserTestCase struct {
Name string
RequestData []byte
ResponseData []byte
ExpectedEvents []EventType
Validate func(t *testing.T, state TestState)
CloseAfterData bool // Whether to close parser after sending data
}
ParserTestCase defines a test case for parser testing
type Request ¶
type Request struct {
Method string
RequestURI string
Proto string
Host string
URL *url.URL
Headers http.Header
}
Request represents a parsed HTTP request
type Response ¶
type Response struct {
StatusCode int
Status string
Proto string
Headers http.Header
IsInterim bool // true for 1xx responses
}
Response represents a parsed HTTP response
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
func NewSession ¶
func NewSession(ctx context.Context, logger *zap.Logger, domain string, conn *connection.Connection, pluginManager *plugins.Manager) *Session
func (*Session) OnInterimResponse ¶
OnInterimResponse handles HTTP interim response callbacks (1xx responses)
func (*Session) OnRequestBody ¶
OnRequestBody handles HTTP request body chunks
func (*Session) OnResponse ¶
OnResponse handles HTTP response callbacks
func (*Session) OnResponseBody ¶
OnResponseBody handles HTTP response body chunks
type TestCallbackOption ¶
type TestCallbackOption func(*TestCallbackRecorder)
TestCallbackOption configures the TestCallbackRecorder
func WithBufferSize ¶
func WithBufferSize(size int) TestCallbackOption
WithBufferSize sets the event channel buffer size
func WithTimeout ¶
func WithTimeout(d time.Duration) TestCallbackOption
WithTimeout sets the default timeout for waiting operations
type TestCallbackRecorder ¶
type TestCallbackRecorder struct {
// contains filtered or unexported fields
}
TestCallbackRecorder captures parser events with channel-based synchronization
func NewTestCallbackRecorder ¶
func NewTestCallbackRecorder(opts ...TestCallbackOption) *TestCallbackRecorder
NewTestCallbackRecorder creates a new test callback recorder
func (*TestCallbackRecorder) CollectEvents ¶
func (r *TestCallbackRecorder) CollectEvents(stopOnDone bool) []Event
CollectEvents collects all events until timeout or done
func (*TestCallbackRecorder) GetState ¶
func (r *TestCallbackRecorder) GetState() TestState
GetState returns the current accumulated state (thread-safe)
func (*TestCallbackRecorder) OnDone ¶
func (r *TestCallbackRecorder) OnDone()
OnDone implements Callbacks
func (*TestCallbackRecorder) OnError ¶
func (r *TestCallbackRecorder) OnError(err error)
OnError implements Callbacks
func (*TestCallbackRecorder) OnInterimResponse ¶
func (r *TestCallbackRecorder) OnInterimResponse(resp *Response)
OnInterimResponse implements Callbacks
func (*TestCallbackRecorder) OnRequest ¶
func (r *TestCallbackRecorder) OnRequest(req *Request, noBody bool)
OnRequest implements Callbacks
func (*TestCallbackRecorder) OnRequestBody ¶
func (r *TestCallbackRecorder) OnRequestBody(data []byte, complete bool)
OnRequestBody implements Callbacks
func (*TestCallbackRecorder) OnResponse ¶
func (r *TestCallbackRecorder) OnResponse(resp *Response, noBody bool)
OnResponse implements Callbacks
func (*TestCallbackRecorder) OnResponseBody ¶
func (r *TestCallbackRecorder) OnResponseBody(data []byte, complete bool)
OnResponseBody implements Callbacks
func (*TestCallbackRecorder) WaitForCompletion ¶
func (r *TestCallbackRecorder) WaitForCompletion() error
WaitForCompletion waits for the OnDone callback or timeout
func (*TestCallbackRecorder) WaitForEvent ¶
func (r *TestCallbackRecorder) WaitForEvent(eventType EventType) (*Event, error)
WaitForEvent waits for a specific event type with timeout
func (*TestCallbackRecorder) WaitForEvents ¶
func (r *TestCallbackRecorder) WaitForEvents(eventTypes ...EventType) ([]*Event, error)
WaitForEvents waits for multiple events in order
func (*TestCallbackRecorder) WaitForEventsFlexible ¶
func (r *TestCallbackRecorder) WaitForEventsFlexible(timeout time.Duration, eventTypes ...EventType) ([]*Event, error)
WaitForEventsFlexible waits for multiple events but allows them to arrive in any order
type TestState ¶
type TestState struct {
Request *Request
RequestBody []byte
RequestComplete bool
InterimResponses []*Response
Response *Response
ResponseBody []byte
ResponseComplete bool
Errors []error
DoneCalled bool
}
TestState represents the accumulated parser state
type TransactionState ¶
type TransactionState struct {
// contains filtered or unexported fields
}
TransactionState coordinates between request and response processors