web

package
v0.0.19 Latest Latest
Warning

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

Go to latest
Published: May 2, 2025 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CompressResponseBody

func CompressResponseBody(resp *http.Response) error

CompressResponseBody compresses the response body using the appropriate compression algorithm.

func DecompressResponseBody

func DecompressResponseBody(resp *http.Response) error

DecompressResponseBody decompresses the response body using the appropriate decompression algorithm.

func InjectJsScript

func InjectJsScript(response *http.Response, data io.Reader) (bool, error)

InjectJsScript injects a JavaScript script into the HTML response body. It injects the script after the <head> tag or before the </body> tag. The location of the script is determined by the first occurrence of the <head> or </body> tag.

func ModifyCSP

func ModifyCSP(csp string, scripts ...[]byte) string

ModifyCSP modifies the Content-Security-Policy header to allow the proxy scripts. Furthermore, it whitelists the target hosts specified in ConfigProxyTargetHosts.

func SessionSave

func SessionSave(session sessions.Session, ctx *gin.Context) (success bool)

SessionSave saves the session and handles any errors that occur. If an error occurs, it displays an error page and aborts the request. It returns true if the session is saved successfully.

func SetContentSecurityHeaders

func SetContentSecurityHeaders(w http.ResponseWriter, nonce string)

SetContentSecurityHeaders sets the Content-Security-Policy, X-Frame-Options, and X-Content-Type-Options headers. It uses the nonce to set the script-src and style-src directives.

Types

type ErrorResponse added in v0.0.15

type ErrorResponse struct {
	Error struct {
		ErrorCode    int    `json:"error_code"`
		ErrorMessage string `json:"error_message"`
	} `json:"error"`
}

ErrorResponse is the response structure for errors from the IP2Location API.

type LookupResponse added in v0.0.15

type LookupResponse struct {
	IP          string  `json:"ip"`
	CountryCode string  `json:"country_code"`
	CountryName string  `json:"country_name"`
	RegionName  string  `json:"region_name"`
	CityName    string  `json:"city_name"`
	Latitude    float64 `json:"latitude"`
	Longitude   float64 `json:"longitude"`
	ZipCode     string  `json:"zip_code"`
	TimeZone    string  `json:"time_zone"`
	Asn         string  `json:"asn"`
	As          string  `json:"as"`
	IsProxy     bool    `json:"is_proxy"`
}

LookupResponse is the response structure for the IP2Location API.

func LookupIP added in v0.0.15

func LookupIP(ip string) (*LookupResponse, error)

LookupIP looks up the IP address using the IP2Location API (https://www.ip2location.io/). It returns geo-location information about the IP address.

type RetryConfig

type RetryConfig struct {
	MaxRetries int           `json:"max_retries,omitempty"`
	RetryCodes []int         `json:"retry_codes,omitempty"`
	RetryDelay time.Duration `json:"-"`
}

RetryConfig is the configuration for the RetryTransport.

func (RetryConfig) MarshalJSON

func (r RetryConfig) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface for RetryConfig.

type RetryTransport

type RetryTransport struct {
	Config RetryConfig
	http.RoundTripper
}

RetryTransport is a custom transport that retries requests on failure.

func (*RetryTransport) RoundTrip

func (t *RetryTransport) RoundTrip(req *http.Request) (response *http.Response, err error)

RoundTrip implements the http.RoundTripper interface for RetryTransport.

Jump to

Keyboard shortcuts

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