request

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BaseURL

func BaseURL(r *http.Request) string

BaseURL returns the base URL for the given request.

func Host

func Host(r *http.Request) string

Host returns the host part of the URL from the request.

func InPath

func InPath(r *http.Request, path string, options ...string) bool

InPath returns true if the current request path matches the given path.

Parameters: - r: *http.Request - the current HTTP request - path: string - the path to match against the request path - options: ...string - optional parameters for matching the path

Returns: - bool: true if the request path matches the given path, false otherwise

Options: - exact: matches the exact path - contains: matches if the path contains the given path - prefix: matches if the path starts with the given path - suffix: matches if the path ends with the given path

func IsFormRequest

func IsFormRequest(r *http.Request) bool

IsFormRequest returns true if the request has a Content-Type of application/x-www-form-urlencoded

func IsJSONRequest

func IsJSONRequest(r *http.Request) bool

IsJSONRequest returns true if the request has a Content-Type of application/json

func IsSecure

func IsSecure(r *http.Request) bool

IsSecure returns true if the current request is using the HTTPS scheme.

func IsXMLHttpRequest

func IsXMLHttpRequest(r *http.Request) bool

IsXMLHttpRequest returns true if the request is an XMLHttpRequest (e.g. via fetch)

func Method

func Method(r *http.Request) string

Method returns the HTTP method of the provided request.

func Port

func Port(r *http.Request) string

Port returns the port number from the HTTP request.

func Referer

func Referer(r *http.Request) string

func RemoteAddr

func RemoteAddr(r *http.Request) string

RemoteAddr returns the client's IP address extracted from the given http.Request. If the server is behind a proxy and the x-forwarded-for header is set, it will return the first IP address in the list. Otherwise, it will check for the x-real-ip header and return its value. If neither header is set, it will return the remote address of the request.

func Scheme

func Scheme(r *http.Request) string

Scheme returns the scheme (http or https) of the given request.

func SchemeHostPort

func SchemeHostPort(r *http.Request) (string, string, string)

SchemeHostPort returns the scheme, host, and port for the given request. If behind a proxy and the X-Forwarded-Proto, X-Forwarded-Host, and/or X-Forwarded-Port headers are set, they will be used.

func URLPath

func URLPath(r *http.Request) string

URLPath returns the path portion of the URL in the given http.Request object.

func UserAgent

func UserAgent(r *http.Request) string

UserAgent returns the value of the User-Agent header from the HTTP request.

Types

This section is empty.

Jump to

Keyboard shortcuts

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