urlutil

package
v0.0.0-...-e4e936e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 7, 2023 License: MIT Imports: 10 Imported by: 0

README

urlutil

The package contains various helpers to interact with URLs

Documentation

Index

Constants

View Source
const (
	HTTP  = "http"
	HTTPS = "https"

	DefaultHTTPPort  = "80"
	DefaultHTTPSPort = "443"
)

Variables

View Source
var AllowLegacySeperator bool = false

Legacy Seperator (i.e `;`) is used as seperator for parameters this was removed in go >=1.17

View Source
var DisableAutoCorrect bool

disables autocorrect related to parsing Ex: if input is admin url.Parse considers admin as host which is not a valid domain name

View Source
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

View Source
var RFCEscapeCharSet []rune = []rune{'!', '*', '\'', '(', ')', ';', ':', '@', '&', '=', '+', '$', ',', '/', '?', '%', '#', '[', ']'}

Reserved Chars from RFC ! * ' ( ) ; : @ & = + $ , / ? % # [ ]

Functions

func AutoMergeRelPaths

func AutoMergeRelPaths(path1 string, path2 string) (string, error)

AutoMergeRelPaths merges two relative paths including parameters and returns final string

func ParamEncode

func ParamEncode(data string) string

ParamEncode encodes Key characters only. key characters include whitespaces + non printable chars + non-ascii also this does not double encode encoded characters

func PercentEncoding

func PercentEncoding(data string) string

PercentEncoding encodes all characters to percent encoded format just like burpsuite decoder

func URLEncodeWithEscapes

func URLEncodeWithEscapes(data string, charset ...rune) string

URLEncodeWithEscapes URL encodes data with given special characters escaped (similar to burpsuite intruder) Note `MustEscapeCharSet` is not included

Types

type Params

type Params map[string][]string

func GetParams

func GetParams(query url.Values) Params

GetParams return Params type using url.Values

func NewParams

func NewParams() Params

func (Params) Add

func (p Params) Add(key string, value ...string)

Add Parameters to store

func (Params) Decode

func (p Params) Decode(raw string)

Decode is opposite of Encode() where ("bar=baz&foo=quux") is parsed Parameters are loosely parsed to allow any scenario

func (Params) Del

func (p Params) Del(key string)

Del deletes values associated with key

func (Params) Encode

func (p Params) Encode() string

Encode URL encodes and returns values ("bar=baz&foo=quux") sorted by key.

func (Params) Get

func (p Params) Get(key string) string

Get returns first value of given key

func (Params) Has

func (p Params) Has(key string) bool

Has returns if given key exists

func (Params) Merge

func (p Params) Merge(x Params)

Merges given paramset into existing one with base as priority

func (Params) Set

func (p Params) Set(key string, value string)

Set sets the key to value and replaces if already exists

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     Params // Query Parameters

}

URL a wrapper around net/url.URL

func Parse

func Parse(inputURL string) (*URL, error)

ParseURL

func ParseURL

func ParseURL(inputURL string, unsafe bool) (*URL, error)

Parse and return URL

func (*URL) Clone

func (u *URL) Clone() *URL

Clone

func (*URL) GetRelativePath

func (u *URL) GetRelativePath() string

GetRelativePath ex: /some/path?param=true#fragment

func (*URL) MergePath

func (u *URL) MergePath(newrelpath string, unsafe bool) error

mergepath merges given relative path

func (*URL) Query

func (u *URL) Query() Params

Query returns Query Params

func (*URL) String

func (u *URL) String() string

String

func (*URL) Update

func (u *URL) Update()

Updates internal wrapped url.URL with any changes done to Query Parameters

func (*URL) UpdatePort

func (u *URL) UpdatePort(newport string)

Updates port

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL