urlutil

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jan 19, 2023 License: MIT Imports: 8 Imported by: 468

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 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 AppendRequestURI

func AppendRequestURI(u, requestURI string) (string, error)

func AutoMergePaths added in v0.0.4

func AutoMergePaths(relpath1 string, relpath2 string) string

AutoMergePaths merges two relative paths including parameters and returns final string

func ChangePort

func ChangePort(u, port string) (string, error)

func ParamEncode added in v0.0.4

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 added in v0.0.4

func PercentEncoding(data string) string

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

func PreprendDefaultScheme

func PreprendDefaultScheme(u string) string

func PreprendScheme

func PreprendScheme(u, scheme string) string

func TrimPort

func TrimPort(host, port string) string

func TrimScheme

func TrimScheme(host string) string

func URLEncodeWithEscapes added in v0.0.4

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 added in v0.0.4

type Params map[string][]string

func GetParams added in v0.0.4

func GetParams(query url.Values) Params

GetParams return Params type using url.Values

func NewParams added in v0.0.4

func NewParams() Params

func (Params) Add added in v0.0.4

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

Add Parameters to store

func (Params) Decode added in v0.0.4

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 added in v0.0.4

func (p Params) Del(key string)

Del deletes values associated with key

func (Params) Encode added in v0.0.4

func (p Params) Encode() string

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

func (Params) Get added in v0.0.4

func (p Params) Get(key string) string

Get returns first value of given key

func (Params) Has added in v0.0.4

func (p Params) Has(key string) bool

Has returns if given key exists

func (Params) Merge added in v0.0.4

func (p Params) Merge(x Params)

Merges given paramset into existing one with base as priority

func (Params) Set added in v0.0.4

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

Set sets the key to value and replaces if already exists

type RawURL added in v0.0.4

type RawURL struct {
	Original string // raw or Original string (excluding params and fragment)
	Path     string // Path is Relative Path
	Unsafe   bool   // when unsafe parsing(host,port etc) is not guaranteed
	Fragment string
	// contains filtered or unexported fields
}

RawURL is wrapper around url.URL that can handle all path and parameters including raw unsafe requests

func ParseURL added in v0.0.4

func ParseURL(uri string, unsafe bool) (*RawURL, error)

ParseURL returns parsed URL

func (*RawURL) MergePath added in v0.0.4

func (r *RawURL) MergePath(relpath string, unsafe bool)

MergePath merges (/blog/admin?user=true + /blog/admin/profile?show=true => /blog/admin/profile?user=true&show=true) and all other edgecases

func (*RawURL) Query added in v0.0.4

func (r *RawURL) Query() Params

Query returns Parameters

func (*RawURL) String added in v0.0.4

func (r *RawURL) String() string

String returns complete url if possible

type URL

type URL struct {
	Scheme     string
	Username   string
	Password   string
	Host       string
	Port       string
	RequestURI string
	Fragment   string
}

func Parse

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

func ParseWithScheme

func ParseWithScheme(u string) (*URL, error)

func (URL) String

func (u URL) String() string

Jump to

Keyboard shortcuts

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