port

package
v3.3.39 Latest Latest
Warning

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

Go to latest
Published: Jul 13, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package port provides utilities for modifying and filtering based on the port of request URLs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Filter

type Filter struct {
	// contains filtered or unexported fields
}

Filter runs modifiers iff the port in the request URL matches port.

func NewFilter

func NewFilter(port int) *Filter

NewFilter returns a filter that executes modifiers if the port of request matches port.

func (*Filter) ModifyRequest

func (f *Filter) ModifyRequest(req *http.Request) error

ModifyRequest runs the modifier if the port matches the provided port.

func (*Filter) ModifyResponse

func (f *Filter) ModifyResponse(res *http.Response) error

ModifyResponse runs the modifier if the request URL matches urlMatcher.

func (*Filter) SetRequestModifier

func (f *Filter) SetRequestModifier(reqmod martian.RequestModifier)

SetRequestModifier sets the request modifier.

func (*Filter) SetResponseModifier

func (f *Filter) SetResponseModifier(resmod martian.ResponseModifier)

SetResponseModifier sets the response modifier.

type Modifier

type Modifier struct {
	// contains filtered or unexported fields
}

Modifier alters the request URL and Host header to use the provided port. Only one of port, defaultForScheme, or remove may be specified. Whichever is set last is the one that will take effect. If remove is true, remove the port from the host string ('example.com'). If defaultForScheme is true, explicitly specify 80 for HTTP or 443 for HTTPS ('http://example.com:80'). Do nothing for a scheme that is not 'http' or 'https'. If port is specified, explicitly add it to the host string ('example.com:1234'). If port is zero and the other fields are false, the request will not be modified.

func NewModifier

func NewModifier() *Modifier

NewModifier returns a RequestModifier that can be configured to alter the request URL and Host header's port. One of DefaultPortForScheme, UsePort, or RemovePort should be called to configure this modifier.

func (*Modifier) DefaultPortForScheme

func (m *Modifier) DefaultPortForScheme()

DefaultPortForScheme configures the modifier to explicitly specify 80 for HTTP or 443 for HTTPS ('http://example.com:80'). The modifier will not modify requests with a scheme that is not 'http' or 'https'. This overrides any previous configuration for this modifier.

func (*Modifier) ModifyRequest

func (m *Modifier) ModifyRequest(req *http.Request) error

ModifyRequest alters the request URL and Host header to modify the port as specified. See docs for Modifier for details.

func (*Modifier) RemovePort

func (m *Modifier) RemovePort()

RemovePort configures the modifier to remove the port from the host string ('example.com'). This overrides any previous configuration for this modifier.

func (*Modifier) UsePort

func (m *Modifier) UsePort(port int)

UsePort configures the modifier to add the specified port to the host string ('example.com:1234'). This overrides any previous configuration for this modifier.

Jump to

Keyboard shortcuts

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