Documentation
¶
Overview ¶
Package httpx containst the httpx common functionality
Index ¶
- Constants
- Variables
- func CanHaveTitleTag(mimeType string) bool
- func DecodeData(data []byte, headers http.Header) ([]byte, error)
- func DecodeKorean(s []byte) ([]byte, error)
- func Decodebig5(s []byte) ([]byte, error)
- func Decodegbk(s []byte) ([]byte, error)
- func DialedIP(ctx context.Context) string
- func Encodebig5(s []byte) ([]byte, error)
- func ExtractGenerator(r *Response) string
- func ExtractTitle(r *Response) (title string)
- func PinnedContext(req *http.Request) context.Context
- func WithHost(ctx context.Context, host, ip string) context.Context
- type BodyDomain
- type CSPData
- type ChainItem
- type CustomCallback
- type Filter
- type FilterCustom
- type FilterRegex
- type FilterString
- type HTTPX
- func (h *HTTPX) AddFilter(f Filter)
- func (h *HTTPX) BodyDomainGrab(r *Response) *BodyDomain
- func (h *HTTPX) CSPGrab(r *Response) *CSPData
- func (h *HTTPX) CdnCheck(ip string) (bool, string, string, error)
- func (h *HTTPX) Do(req *retryablehttp.Request, unsafeOptions UnsafeOptions) (*Response, error)
- func (h *HTTPX) IsVirtualHost(req *retryablehttp.Request, unsafeOptions UnsafeOptions) (bool, error)
- func (h *HTTPX) NewRequest(method, targetURL string) (req *retryablehttp.Request, err error)
- func (h *HTTPX) NewRequestWithContext(ctx context.Context, method, targetURL string) (req *retryablehttp.Request, err error)
- func (httpx *HTTPX) Sanitize(respStr string, trimLine, normalizeSpaces bool) string
- func (h *HTTPX) SetCustomHeaders(r *retryablehttp.Request, headers map[string][]string)
- func (h *HTTPX) SupportHTTP2(protocol, method, targetURL string) bool
- func (h *HTTPX) SupportPipeline(protocol, method, host string, port int) bool
- func (h *HTTPX) TLSGrab(r *http.Response) *clients.Response
- func (h *HTTPX) Verify(req *retryablehttp.Request, unsafeOptions UnsafeOptions) (bool, error)
- func (h *HTTPX) ZTLSGrab(r *http.Response) *clients.Response
- type Options
- type Proto
- type Response
- func (r *Response) GetChain() string
- func (r *Response) GetChainAsSlice() (chain []ChainItem)
- func (r *Response) GetChainLastURL() string
- func (r *Response) GetChainStatusCodes() []int
- func (r *Response) GetHeader(name string) string
- func (r *Response) GetHeaderPart(name, sep string) string
- func (r *Response) HasChain() bool
- type Target
- type UnsafeOptions
Constants ¶
const ( // HTTP defines the plain http scheme HTTP = "http" // HTTPS defines the secure http scheme HTTPS = "https" // HTTPorHTTPS defines both http and https scheme in mutual exclusion HTTPorHTTPS = "http|https" // HTTPandHTTPS defines both http and https scheme HTTPandHTTPS = "http&https" )
Variables ¶
var CSPHeaders = []string{
"Content-Security-Policy",
"Content-Security-Policy-Report-Only",
"X-Content-Security-Policy-Report-Only",
"X-Webkit-Csp-Report-Only",
}
CSPHeaders is an incomplete list of most common CSP headers
var DefaultMaxResponseBodySize = func() int64 { maxResponseBodySize, _ := humanize.ParseBytes("50mb") return int64(maxResponseBodySize) }()
DefaultMaxResponseBodySize is the default maximum response body size that httpx reads into memory for processing (and, via the runner, the default cap for responses stored to disk with -sr). It is intentionally bounded: the body is held in memory and the footprint scales with the number of concurrent threads, so a very large cap can lead to excessive memory usage / OOM on large responses. Normal web pages are far smaller than this; use -rstr / -rsts to read or store larger responses when needed.
NOTE: this is a var initializer (not an init() function) on purpose. init() functions run after all package-level variable initializers, so computing the value in init() left DefaultOptions (which references it below) observing a zero value during package initialization.
var DefaultOptions = Options{ RandomAgent: true, Threads: 25, Timeout: 30 * time.Second, RetryMax: 5, MaxRedirects: 10, Unsafe: false, CdnCheck: "true", ExcludeCdn: false, MaxResponseBodySizeToRead: DefaultMaxResponseBodySize, VHostIgnoreStatusCode: false, VHostIgnoreContentLength: true, VHostIgnoreNumberOfWords: false, VHostIgnoreNumberOfLines: false, VHostStripHTML: false, VHostSimilarityRatio: 85, DefaultUserAgent: "httpx - Open-source project (github.com/projectdiscovery/httpx)", }
DefaultOptions contains the default options
var ErrPinnedThroughProxy = errors.New("a host pinned to an ip cannot be reached through a proxy")
ErrPinnedThroughProxy is the error of a request to a pinned host that would go through a proxy, which resolves the host itself.
Functions ¶
func CanHaveTitleTag ¶ added in v1.6.1
func DecodeData ¶ added in v1.2.3
DecodeData converts a response body that is not UTF-8 to UTF-8, using the charset declared in the Content-Type header or in the page itself.
func DecodeKorean ¶ added in v1.2.0
func Decodebig5 ¶ added in v0.0.7
Decodebig5 converts BIG5 to UTF-8
func DialedIP ¶ added in v1.13.0
DialedIP returns the ip of the last connection dialed to the host of a WithHost context, or "" if none was.
func Encodebig5 ¶ added in v0.0.7
Encodebig5 converts UTF-8 to BIG5
func ExtractGenerator ¶ added in v1.13.0
ExtractGenerator extracts the content of <meta name="generator"> from a response.
func PinnedContext ¶ added in v1.13.0
PinnedContext returns a new context for another request derived from req, in which the host of req keeps the ip it is pinned to. The other values of the context of req, such as a trace, are not kept.
func WithHost ¶ added in v1.13.0
WithHost returns a copy of ctx for requests to host. When ip is set, they connect to it, like curl --resolve but on every port of host, while the host keeps its name for the Host header and SNI. The ip they are dialed to is recorded for DialedIP, while the dialer only keeps the last ip dialed to a host by any request. Requests to other hosts, such as redirect targets, are resolved as usual and not recorded.
Types ¶
type BodyDomain ¶ added in v1.6.4
type CSPData ¶ added in v1.0.3
type CSPData struct {
Fqdns []string `json:"fqdn,omitempty"`
Domains []string `json:"domains,omitempty"`
}
CSPData contains the Content-Security-Policy domain list
type ChainItem ¶ added in v1.0.6
type ChainItem struct {
Request string `json:"request,omitempty"`
Response string `json:"response,omitempty"`
StatusCode int `json:"status_code,omitempty"`
Location string `json:"location,omitempty"`
RequestURL string `json:"request-url,omitempty"`
}
ChainItem request=>response
type CustomCallback ¶
CustomCallback used in custom filters
type FilterCustom ¶
type FilterCustom struct {
CallBacks []CustomCallback
}
FilterCustom defines a filter with callback functions applied
type FilterRegex ¶
type FilterRegex struct {
Regexs []string
}
FilterRegex defines a filter of type regex
type FilterString ¶
type FilterString struct {
Keywords []string
}
FilterString defines a filter of type string
type HTTPX ¶
type HTTPX struct {
Filters []Filter
Options *Options
CustomHeaders map[string][]string
Dialer *fastdialer.Dialer
NetworkPolicy *networkpolicy.NetworkPolicy
// contains filtered or unexported fields
}
HTTPX represent an instance of the library client
func (*HTTPX) BodyDomainGrab ¶ added in v1.6.4
func (h *HTTPX) BodyDomainGrab(r *Response) *BodyDomain
func (*HTTPX) CdnCheck ¶ added in v1.0.3
CdnCheck verifies if the given ip is part of Cdn/WAF ranges
func (*HTTPX) Do ¶
func (h *HTTPX) Do(req *retryablehttp.Request, unsafeOptions UnsafeOptions) (*Response, error)
Do http request
func (*HTTPX) IsVirtualHost ¶
func (h *HTTPX) IsVirtualHost(req *retryablehttp.Request, unsafeOptions UnsafeOptions) (bool, error)
IsVirtualHost checks if the target endpoint is a virtual host
func (*HTTPX) NewRequest ¶
func (h *HTTPX) NewRequest(method, targetURL string) (req *retryablehttp.Request, err error)
NewRequest from url
func (*HTTPX) NewRequestWithContext ¶ added in v1.1.4
func (h *HTTPX) NewRequestWithContext(ctx context.Context, method, targetURL string) (req *retryablehttp.Request, err error)
NewRequest from url
func (*HTTPX) SetCustomHeaders ¶
func (h *HTTPX) SetCustomHeaders(r *retryablehttp.Request, headers map[string][]string)
SetCustomHeaders on the provided request
func (*HTTPX) SupportHTTP2 ¶ added in v1.0.0
SupportHTTP2 checks if the target host supports HTTP2
func (*HTTPX) SupportPipeline ¶ added in v1.0.0
SupportPipeline checks if the target host supports HTTP1.1 pipelining by sending x probes and reading back responses expecting at least 2 with HTTP/1.1 or HTTP/1.0
func (*HTTPX) Verify ¶
func (h *HTTPX) Verify(req *retryablehttp.Request, unsafeOptions UnsafeOptions) (bool, error)
Verify the http calls and apply-cascade all the filters, as soon as one matches it returns true
type Options ¶
type Options struct {
RandomAgent bool
AutoReferer bool
DefaultUserAgent string
Proxy string
// Deprecated: use Proxy
HTTPProxy string
// Deprecated: use Proxy
SocksProxy string
Threads int
CdnCheck string
ExcludeCdn bool
ExtractFqdn bool
// ExtractCSP extracts the domains of the Content-Security-Policy
ExtractCSP bool
// Timeout is the maximum time to wait for the request
Timeout time.Duration
// RetryMax is the maximum number of retries
RetryMax int
CustomHeaders map[string][]string
// VHostSimilarityRatio 1 - 100
VHostSimilarityRatio int
FollowRedirects bool
FollowHostRedirects bool
RespectHSTS bool
MaxRedirects int
Unsafe bool
TLSGrab bool
ZTLS bool
// VHOSTs options
VHostIgnoreStatusCode bool
VHostIgnoreContentLength bool
VHostIgnoreNumberOfWords bool
VHostIgnoreNumberOfLines bool
VHostStripHTML bool
MaxResponseBodySizeToSave int64
MaxResponseBodySizeToRead int64
UnsafeURI string
Resolvers []string
SniName string
TlsImpersonate string
NetworkPolicy *networkpolicy.NetworkPolicy
CDNCheckClient *cdncheck.Client
Protocol Proto
Trace bool
AuthProvider authprovider.AuthProvider
// contains filtered or unexported fields
}
Options contains configuration options for the client
type Response ¶
type Response struct {
Input string // input that was given
StatusCode int
Headers map[string][]string
RawData []byte // undecoded data
Data []byte // decoded data
ContentLength int
Raw string
RawHeaders string
Words int
Lines int
TLSData *clients.Response
CSPData *CSPData
BodyDomains *BodyDomain
HTTP2 bool
Pipeline bool
Duration time.Duration
Chain []httputil.ChainItem
}
Response contains the response to a server
func (*Response) GetChainAsSlice ¶ added in v1.0.6
GetChainAsSlice dump the whole redirect chain as structuerd slice
func (*Response) GetChainLastURL ¶ added in v1.0.7
GetChainLastURL returns the final URL
func (*Response) GetChainStatusCodes ¶ added in v1.0.6
GetChainStatusCodes from redirects
func (*Response) GetHeaderPart ¶ added in v0.0.7
GetHeaderPart with offset
type UnsafeOptions ¶ added in v1.1.2
type UnsafeOptions struct {
URIPath string
}
RequestOverride contains the URI path to override the request