Documentation
¶
Index ¶
- Constants
- Variables
- func AutoMergeRelPaths(path1 string, path2 string) (string, error)
- func ParamEncode(data string) string
- func PathDecode(data string) (string, error)
- func PathEncode(data string) string
- func PercentEncoding(data string) string
- func URLEncodeWithEscapes(data string, charset ...rune) string
- type OrderedParams
- func (o *OrderedParams) Add(key string, value ...string)
- func (o *OrderedParams) Clone() *OrderedParams
- func (o *OrderedParams) Decode(raw string)
- func (o *OrderedParams) Del(key string)
- func (o *OrderedParams) Encode() string
- func (o *OrderedParams) Get(key string) string
- func (o *OrderedParams) GetAll(key string) []string
- func (o *OrderedParams) Has(key string) bool
- func (o *OrderedParams) IsEmpty() bool
- func (o *OrderedParams) Iterate(f func(key string, value []string) bool)
- func (o *OrderedParams) Merge(raw string)
- func (o *OrderedParams) Set(key string, value string)
- func (o *OrderedParams) Update(key string, value []string)
- type Params
- func (p Params) Add(key string, value ...string)
- func (p Params) Decode(raw string)
- func (p Params) Del(key string)
- func (p Params) Encode() string
- func (p Params) Get(key string) string
- func (p Params) Has(key string) bool
- func (p Params) Merge(x Params)
- func (p Params) Set(key string, value string)
- type URL
- func Parse(inputURL string) (*URL, error)
- func ParseAbsoluteURL(inputURL string, unsafe bool) (*URL, error)
- func ParseRawRelativePath(inputURL string, unsafe bool) (*URL, error)
- func ParseRelativePath(inputURL string, unsafe bool) (*URL, error)
- func ParseURL(inputURL string, unsafe bool) (*URL, error)
- func (u *URL) Clone() *URL
- func (u *URL) EscapedString() string
- func (u *URL) GetRelativePath() string
- func (u *URL) MergePath(newrelpath string, unsafe bool) error
- func (u *URL) Query() *OrderedParams
- func (u *URL) String() string
- func (u *URL) TrimPort()
- func (u *URL) Update()
- func (u *URL) UpdatePort(newport string)
- func (u *URL) UpdateRelPath(newrelpath string, unsafe bool) error
Constants ¶
const ( HTTP = "http" HTTPS = "https" // Deny all protocols // Allow: // websocket + websocket over ssl WEBSOCKET = "ws" WEBSOCKET_SSL = "wss" FTP = "ftp" SchemeSeparator = "://" DefaultHTTPPort = "80" DefaultHTTPSPort = "443" )
Variables ¶
var AllowLegacySeperator bool = false
Legacy Seperator (i.e `;`) is used as seperator for parameters this was removed in go >=1.17
var MustEscapeCharSet []rune = []rune{'?', '#', '@', ';', '&', ',', '[', ']', '^'}
MustEscapeCharSet are special chars that are always escaped and are based on reserved chars from RFC Some of Reserved Chars From RFC were excluded and some were added for various reasons and goal here is to encode parameters key and value only
var PathMustEscapeCharSet []rune = []rune{'?', '#', '@', ';', ',', '[', ']', '^'}
PathMustEscapeCharSet are characters that must be escaped in URL paths Different from query params: & = don't need escaping, but / # ? do need escaping
var RFCEscapeCharSet []rune = []rune{'!', '*', '\'', '(', ')', ';', ':', '@', '&', '=', '+', '$', ',', '/', '?', '%', '#', '[', ']'}
Reserved Chars from RFC ! * ' ( ) ; : @ & = + $ , / ? % # [ ]
Functions ¶
func AutoMergeRelPaths ¶ added in v0.0.6
AutoMergeRelPaths merges two relative paths including parameters and returns final string
func ParamEncode ¶ added in v0.0.4
ParamEncode encodes Key characters only. key characters include whitespaces + non printable chars + non-ascii also this does not double encode encoded characters
func PathDecode ¶ added in v0.5.0
PathDecode decodes path segments with path-specific rules Key differences from param decoding: 1. + is treated as literal + character (not space) 2. Only %20 decodes to space
func PathEncode ¶ added in v0.5.0
PathEncode encodes path segments with path-specific rules Key differences from ParamEncode: 1. Always uses %20 for spaces (never +) 2. & and = don't need escaping in paths 3. / # ? must be escaped as they have special meaning in paths
func PercentEncoding ¶ added in v0.0.4
PercentEncoding encodes all characters to percent encoded format just like burpsuite decoder
func URLEncodeWithEscapes ¶ added in v0.0.4
URLEncodeWithEscapes URL encodes data with given special characters escaped (similar to burpsuite intruder) Note `MustEscapeCharSet` is not included
Types ¶
type OrderedParams ¶ added in v0.0.40
type OrderedParams struct {
// IncludeEquals controls whether "=" is appended when an empty
// value is encoded. It applies only to programmatically
// added/mutated parameters - parameters that came from Decode
// keep the "=" (or lack thereof) they had originally.
IncludeEquals bool
// contains filtered or unexported fields
}
OrderedParams keeps query parameters in insertion order and, for parameters parsed from a query string, preserves the exact original byte form so the string round-trips through Encode unchanged.
Programmatically added or mutated parameters are encoded using ParamEncode and the IncludeEquals flag, matching the historical behavior of this type.
func NewOrderedParams ¶ added in v0.0.40
func NewOrderedParams() *OrderedParams
NewOrderedParams creates a new ordered params
func (*OrderedParams) Add ¶ added in v0.0.40
func (o *OrderedParams) Add(key string, value ...string)
Add appends one entry per value to the store. Calling Add with no values is a no-op.
func (*OrderedParams) Clone ¶ added in v0.0.40
func (o *OrderedParams) Clone() *OrderedParams
Clone returns a deep copy of the OrderedParams.
func (*OrderedParams) Decode ¶ added in v0.0.40
func (o *OrderedParams) Decode(raw string)
Decode parses raw and appends its parameters to the current store. Each segment's original byte form is remembered so that an unmodified Decode+Encode round-trip produces an identical string. Parameters are loosely parsed to allow any scenario.
func (*OrderedParams) Del ¶ added in v0.0.40
func (o *OrderedParams) Del(key string)
Del removes every entry whose key matches.
func (*OrderedParams) Encode ¶ added in v0.0.40
func (o *OrderedParams) Encode() string
Encode returns the encoded query string. Entries that came from Decode are emitted verbatim, preserving the original byte form (including whether "=" was present and the exact escaping). Entries added programmatically use ParamEncode and the IncludeEquals flag.
func (*OrderedParams) Get ¶ added in v0.0.40
func (o *OrderedParams) Get(key string) string
Get returns the first value associated with key, or "" if absent.
func (*OrderedParams) GetAll ¶ added in v0.0.40
func (o *OrderedParams) GetAll(key string) []string
GetAll returns every value associated with key in insertion order, or an empty slice if key is absent.
func (*OrderedParams) Has ¶ added in v0.0.40
func (o *OrderedParams) Has(key string) bool
Has reports whether key is present.
func (*OrderedParams) IsEmpty ¶ added in v0.0.40
func (o *OrderedParams) IsEmpty() bool
IsEmpty checks if the OrderedParams is empty
func (*OrderedParams) Iterate ¶ added in v0.0.40
func (o *OrderedParams) Iterate(f func(key string, value []string) bool)
Iterate iterates over the OrderedParams. Entries that share a key are grouped and the callback receives every key exactly once, in the order of its first appearance, together with the full list of decoded values for that key.
func (*OrderedParams) Merge ¶ added in v0.0.40
func (o *OrderedParams) Merge(raw string)
Merge parses raw and appends its parameters to the current store.
func (*OrderedParams) Set ¶ added in v0.0.40
func (o *OrderedParams) Set(key string, value string)
Set replaces all values of key with a single value. The position of the first occurrence of key is preserved; later occurrences are removed. If the key is missing it is appended at the end.
func (*OrderedParams) Update ¶ added in v0.0.40
func (o *OrderedParams) Update(key string, value []string)
Update replaces every value associated with key by the given slice. If key already exists the replacement keeps its position in the insertion order; otherwise the new values are appended.
type Params ¶ added in v0.0.4
func (Params) Decode ¶ added in v0.0.4
Decode is opposite of Encode() where ("bar=baz&foo=quux") is parsed Parameters are loosely parsed to allow any scenario
func (Params) Encode ¶ added in v0.0.4
Encode URL encodes and returns values ("bar=baz&foo=quux") sorted by key.
type URL ¶
type URL struct {
*url.URL
Original string // original or given url(without params if any)
Unsafe bool // If request is unsafe (skip validation)
IsRelative bool // If URL is relative
Params *OrderedParams // Query Parameters
// contains filtered or unexported fields
}
URL a wrapper around net/url.URL
func ParseAbsoluteURL ¶ added in v0.0.69
ParseAbsoluteURL parses and returns absolute url should be preferred over others when input is known to be absolute url this reduces any normalization and autocorrection related to relative paths and returns error if input is relative path
func ParseRawRelativePath ¶ added in v0.0.69
ParseRelativePath
func ParseRelativePath ¶ added in v0.0.8
ParseRelativePath parses and returns relative path should be preferred over others when input is known to be relative path this reduces any normalization and autocorrection related to absolute paths and returns error if input is absolute path
func (*URL) EscapedString ¶ added in v0.0.8
EscapedString returns a string that can be used as filename (i.e stripped of / and params etc)
func (*URL) GetRelativePath ¶ added in v0.0.6
GetRelativePath ex: /some/path?param=true#fragment