Documentation
¶
Overview ¶
Package ftwhttp provides low level abstractions for sending/receiving raw http messages
Index ¶
- Constants
- func BuildRequest(r *Request) ([]byte, error)
- type Client
- func (c *Client) Do(req Request) (*Response, error)
- func (c *Client) GetRoundTripTime() *RoundTripTime
- func (c *Client) NewConnection(d Destination) error
- func (c *Client) NewOrReusedConnection(d Destination) error
- func (c *Client) SetRateLimiter(limiter *rate.Limiter)
- func (c *Client) SetRootCAs(cas *x509.CertPool)
- func (c *Client) StartTrackingTime()
- func (c *Client) StopTrackingTime()
- type ClientConfig
- type Connection
- type Destination
- type FTWConnection
- type Header
- func (h *Header) Add(name string, value string)
- func (h *Header) Clone() *Header
- func (h *Header) GetAll(name string) []HeaderTuple
- func (h *Header) HasAny(name string) bool
- func (h *Header) HasAnyValue(name string, value string) bool
- func (h *Header) HasAnyValueContaining(name string, value string) bool
- func (h *Header) Set(name string, value string)
- func (h *Header) Write(writer io.Writer) error
- type HeaderTuple
- type Request
- func (r *Request) AddHeader(name string, value string)
- func (r *Request) AddStandardHeaders()
- func (r Request) Data() []byte
- func (r Request) Headers() *Header
- func (r *Request) SetAutoCompleteHeaders(value bool)
- func (r *Request) SetData(data []byte)
- func (r *Request) SetHeaders(h *Header)
- func (r Request) WithAutoCompleteHeaders() bool
- type RequestLine
- type Response
- type RoundTripTime
Constants ¶
const ( // HeaderSeparator is used to separate header name and value HeaderSeparator = ": " // HeaderDelimiter marks then end of a header (CRLF) HeaderDelimiter = "\r\n" )
Variables ¶
This section is empty.
Functions ¶
func BuildRequest ¶
The request should be created with anything we want. We want to actually break HTTP.
Types ¶
type Client ¶
type Client struct {
Transport *Connection
Jar http.CookieJar
// contains filtered or unexported fields
}
Client is the top level abstraction in http
func NewClient ¶
func NewClient(runnerConfig *config.RunnerConfig) (*Client, error)
NewClient initializes the http client, creating the cookiejar
func NewClientWithConfig ¶
func NewClientWithConfig(config *ClientConfig) (*Client, error)
NewClient initializes the http client, creating the cookiejar
func (*Client) GetRoundTripTime ¶
func (c *Client) GetRoundTripTime() *RoundTripTime
GetRoundTripTime returns the time taken from the initial send till receiving the full response
func (*Client) NewConnection ¶
func (c *Client) NewConnection(d Destination) error
NewConnection creates a new Connection based on a Destination
func (*Client) NewOrReusedConnection ¶
func (c *Client) NewOrReusedConnection(d Destination) error
NewOrReusedConnection reuses an existing connection, or creates a new one if no connection has been set up yet
func (*Client) SetRateLimiter ¶
SetRateLimiter sets the rate limiter for the client.
func (*Client) SetRootCAs ¶
SetRootCAs sets the root CAs for the client. This can be used if you are using internal certificates and for testing purposes.
func (*Client) StartTrackingTime ¶
func (c *Client) StartTrackingTime()
StartTrackingTime sets the timer to start transactions. This will be the starting time in logs.
func (*Client) StopTrackingTime ¶
func (c *Client) StopTrackingTime()
StopTrackingTime stops the timer. When looking at logs, we will read up to this one.
type ClientConfig ¶
type ClientConfig struct {
// ConnectTimeout is the timeout for connecting to a server.
ConnectTimeout time.Duration
// ReadTimeout is the timeout for reading a response.
ReadTimeout time.Duration
// RootCAs is the set of root CA certificates that is used to verify server
RootCAs *x509.CertPool
// RateLimiter is the rate limiter to use for requests.
RateLimiter *rate.Limiter
// SkipTlsVerification skips certificate validation. Useful for connecting
// to domains with a self-signed certificate.
SkipTlsVerification bool
}
ClientConfig provides configuration options for the HTTP client.
func NewClientConfig ¶
func NewClientConfig() *ClientConfig
func NewClientConfigFromConfig ¶
func NewClientConfigFromConfig(runnerConfig *config.RunnerConfig) *ClientConfig
NewClientConfig returns a new ClientConfig with reasonable defaults.
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection is the type used for sending/receiving data
func (*Connection) GetTrackedTime ¶
func (c *Connection) GetTrackedTime() *RoundTripTime
GetTrackedTime will return the time since the request started and the response was parsed
func (*Connection) Request ¶
func (c *Connection) Request(request *Request) error
Request will use all the inputs and send a raw http request to the destination
func (*Connection) Response ¶
func (c *Connection) Response() (*Response, error)
Response reads the response sent by the WAF and return the corresponding struct It leverages the go stdlib for reading and parsing the response
func (*Connection) StartTrackingTime ¶
func (c *Connection) StartTrackingTime()
StartTrackingTime initializes timer
func (*Connection) StopTrackingTime ¶
func (c *Connection) StopTrackingTime()
StopTrackingTime stops timer
type Destination ¶
type Destination struct {
DestAddr string `default:"localhost"`
Port int `default:"80"`
Protocol string `default:"http"`
}
Destination is the host, port and protocol to be used when connecting to a remote host
func DestinationFromString ¶
func DestinationFromString(urlString string) (*Destination, error)
DestinationFromString create a Destination from String
type FTWConnection ¶
type FTWConnection interface {
Request(*Request)
Response(*Response)
GetTrackedTime() *RoundTripTime
// contains filtered or unexported methods
}
FTWConnection is the interface method implement to send and receive data
type Header ¶
type Header struct {
// contains filtered or unexported fields
}
Header is a representation of the HTTP header section. It holds an ordered list of HeaderTuples.
func NewHeader ¶
func NewHeader() *Header
Creates an empty Header. You should not initialize the struct directly.
func NewHeaderWithEntries ¶
func NewHeaderWithEntries(entries []*HeaderTuple) *Header
Creates an empty Header. You should not initialize the struct directly.
func (*Header) Clone ¶
Creates a clone of the Header. If the Header is nil or empty, a non-nil empty Header will be returned.
func (*Header) GetAll ¶
func (h *Header) GetAll(name string) []HeaderTuple
Returns all HeaderTuples that match the canonical header name. If no matches are found the returned array will be empty.
func (*Header) HasAny ¶
Returns true if the Header contains any HTTP header that matches the canonical name.
func (*Header) HasAnyValue ¶
Returns true if the Header contains any HTTP header that matches the canonical name and canoncial value. Values are compared using strings.EqualFold.
func (*Header) HasAnyValueContaining ¶
Returns true if the Header contains any HTTP header that matches the canonical name and has a value containing the specified substring. Both, the header value and the search string are lower-cased before performing the search.
type HeaderTuple ¶
HeaderTuple is a representation of an HTTP header. It consists of a name and value.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request represents a request This struct without defaults represents the previous "autocomplete headers" behavior
func NewRawRequest ¶
NewRawRequest creates a new request from raw data
func NewRequest ¶
func NewRequest(reqLine *RequestLine, h *Header, data []byte, autocompleteHeaders bool) *Request
NewRequest creates a new request, an initial request line, and headers
func (*Request) AddStandardHeaders ¶
func (r *Request) AddStandardHeaders()
AddStandardHeaders adds standard headers to the request, if they don't exist
AddStandardHeaders does the following:
- adds `Connection` header with `close` value (if not set) to improve performance
- adds `Content-Length` header if payload size > 0 or the request method permits a body (the spec says that the client SHOULD send `Content-Length` in that case)
func (*Request) SetAutoCompleteHeaders ¶
SetAutoCompleteHeaders sets the value to the corresponding bool
func (*Request) SetHeaders ¶
SetHeaders sets the request headers
func (Request) WithAutoCompleteHeaders ¶
WithAutoCompleteHeaders returns true when we need to add additional headers to complete the request
type RequestLine ¶
type RequestLine struct {
Method string `default:"GET"`
Version string `default:"HTTP/1.1"`
URI string `default:"/"`
}
RequestLine is the first line in the HTTP request dialog
func (RequestLine) ToString ¶
func (rl RequestLine) ToString() string
ToString converts the request line to string for sending it in the wire
type Response ¶
Response represents the http response received from the server/waf
func (*Response) GetFullResponse ¶
GetFullResponse gives the full response as string, or nil if there was some error
type RoundTripTime ¶
type RoundTripTime struct {
// contains filtered or unexported fields
}
RoundTripTime abstracts the time a transaction takes
func NewRoundTripTime ¶
func NewRoundTripTime() *RoundTripTime
NewRoundTripTime initializes a roundtriptime struct
func (*RoundTripTime) RoundTripDuration ¶
func (rtt *RoundTripTime) RoundTripDuration() time.Duration
RoundTripDuration gives the total time spent in this roundtrip
func (*RoundTripTime) StartTime ¶
func (rtt *RoundTripTime) StartTime() time.Time
StartTime returns the time when this round trip started
func (*RoundTripTime) StartTracking ¶
func (rtt *RoundTripTime) StartTracking()
StartTracking sets the initial time to Now
func (*RoundTripTime) StopTime ¶
func (rtt *RoundTripTime) StopTime() time.Time
StopTime returns the time when this round trip was stopped
func (*RoundTripTime) StopTracking ¶
func (rtt *RoundTripTime) StopTracking()
StopTracking sets the finish time to Now