request

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2022 License: Apache-2.0 Imports: 5 Imported by: 2

Documentation

Overview

Client request module.

A set of functions to retrieve information about the incoming requests made by clients.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Request

type Request struct {
	bridge.PdkBridge
}

Holds this module's functions. Accessible as `kong.Request`

func (Request) GetForwardedHost

func (r Request) GetForwardedHost() (host string, err error)

kong.Request.GetForwardedHost() returns the host component of the request’s URL or the value of the “host” header. Unlike kong.Request.GetHost(), this function will also consider X-Forwarded-Host if it comes from a trusted source. The returned value is normalized to lower-case.

Whether this function considers X-Forwarded-Proto or not depends on several Kong configuration parameters:

  • trusted_ips
  • real_ip_header
  • real_ip_recursive

Note: we do not currently offer support for Forwarded HTTP Extension (RFC 7239) since it is not supported by ngx_http_realip_module.

func (Request) GetForwardedPort

func (r Request) GetForwardedPort() (int, error)

kong.Request.GetForwardedPort() returns the port component of the request’s URL, but also considers X-Forwarded-Host if it comes from a trusted source.

Whether this function considers X-Forwarded-Proto or not depends on several Kong configuration parameters:

  • trusted_ips
  • real_ip_header
  • real_ip_recursive

Note: we do not currently offer support for Forwarded HTTP Extension (RFC 7239) since it is not supported by ngx_http_realip_module.

func (Request) GetForwardedScheme

func (r Request) GetForwardedScheme() (s string, err error)

kong.Request.GetForwardedScheme() returns the scheme component of the request’s URL, but also considers X-Forwarded-Proto if it comes from a trusted source. The returned value is normalized to lower-case.

Whether this function considers X-Forwarded-Proto or not depends on several Kong configuration parameters:

  • trusted_ips
  • real_ip_header
  • real_ip_recursive

Note: support for the Forwarded HTTP Extension (RFC 7239) is not offered yet since it is not supported by ngx_http_realip_module.

func (Request) GetHeader

func (r Request) GetHeader(k string) (string, error)

kong.Request.GetHeader() returns the value of the specified request header.

The returned value is either a string, or can be nil if a header with name was not found in the request. If a header with the same name is present multiple times in the request, this function will return the value of the first occurrence of this header.

Header names in are case-insensitive and are normalized to lowercase, and dashes (-) can be written as underscores (_); that is, the header X-Custom-Header can also be retrieved as x_custom_header.

func (Request) GetHeaders

func (r Request) GetHeaders(max_headers int) (map[string][]string, error)

kong.Request.GetHeaders() returns a map holding the request headers. Keys are header names. Values are either a string with the header value, or an array of strings if a header was sent multiple times. Header names in this table are case-insensitive and are normalized to lowercase, and dashes (-) can be written as underscores (_); that is, the header X-Custom-Header can also be retrieved as x_custom_header.

The max_args argument specifies the maximum number of returned headers. Must be greater than 1 and not greater than 1000, or -1 to specify the default limit of 100 headers.

func (Request) GetHost

func (r Request) GetHost() (host string, err error)

kong.Request.GetHost() returns the host component of the request’s URL, or the value of the “Host” header. The returned value is normalized to lower-case form.

func (Request) GetHttpVersion

func (r Request) GetHttpVersion() (version float64, err error)

kong.Request.GetHttpVersion() returns the HTTP version used by the client in the request, returning values such as "1"", "1.1", "2.0", or nil for unrecognized values.

func (Request) GetMethod

func (r Request) GetMethod() (m string, err error)

kong.Request.GetMethod() returns the HTTP method of the request. The value is normalized to upper-case.

func (Request) GetPath

func (r Request) GetPath() (string, error)

kong.Request.GetPath() returns the path component of the request’s URL. It is not normalized in any way and does not include the querystring.

func (Request) GetPathWithQuery

func (r Request) GetPathWithQuery() (string, error)

kong.Request.GetPathWithQuery() returns the path, including the querystring if any. No transformations/normalizations are done.

func (Request) GetPort

func (r Request) GetPort() (int, error)

kong.Request.GetPort() returns the port component of the request’s URL.

func (Request) GetQuery

func (r Request) GetQuery(max_args int) (map[string][]string, error)

kong.Request.GetQuery() returns a map of query arguments obtained from the querystring. Keys are query argument names. Values are either a string with the argument value, a boolean true if an argument was not given a value, or an array if an argument was given in the query string multiple times. Keys and values are unescaped according to URL-encoded escaping rules.

Note that a query string `?foo&bar` translates to two boolean true arguments, and ?foo=&bar= translates to two string arguments containing empty strings.

The max_args argument specifies the maximum number of returned arguments. Must be greater than 1 and not greater than 1000, or -1 to specify the default limit of 100 arguments.

func (Request) GetQueryArg

func (r Request) GetQueryArg(k string) (string, error)

kong.Request.GetQueryArg() returns the value of the specified argument, obtained from the query arguments of the current request.

The returned value is either a string, a boolean true if an argument was not given a value, or nil if no argument with name was found.

If an argument with the same name is present multiple times in the querystring, this function will return the value of the first occurrence.

func (Request) GetRawBody

func (r Request) GetRawBody() ([]byte, error)

kong.Request.GetRawBody() returns the plain request body.

If the body has no size (empty), this function returns an empty string.

If the size of the body is greater than the Nginx buffer size (set by client_body_buffer_size), this function will fail and return an error message explaining this limitation.

func (Request) GetRawQuery

func (r Request) GetRawQuery() (string, error)

kong.Request.GetRawQuery() returns the query component of the request’s URL. It is not normalized in any way (not even URL-decoding of special characters) and does not include the leading ? character.

func (Request) GetScheme

func (r Request) GetScheme() (s string, err error)

kong.Request.GetScheme() returns the scheme component of the request’s URL. The returned value is normalized to lower-case form.

Jump to

Keyboard shortcuts

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