internal

package
v2.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const XBLRelyingParty = "http://xboxlive.com"

XBLRelyingParty is the relying party used for various Xbox Live services. In XSAPI Client, it will be used for requesting NSAL endpoints for current authenticated title.

Variables

DefaultLanguage is an AcceptLanguage option that appends American English and English as fallback language preferences to the 'Accept-Language' header. It is intended to be appended after any caller-provided options so that it always appears as the lowest-priority suffix in the header value.

Functions

func Apply

func Apply(req *http.Request, opts []RequestOption)

Apply applies the given RequestOptions to the request in order. Caller-provided opts take precedence over any defaults appended after them. For example, append caller opts before defaults like append(opts, internal.DefaultLanguage) so that the caller's preferences are evaluated first.

func Do

func Do(ctx context.Context, client *http.Client, method, u string, reqBody, respBody any, opts []RequestOption) error

Do sends an HTTP request to the given URL using the provided client.

If reqBody is non-nil, it is JSON-encoded and sent as the request body with the 'Content-Type' header set to 'application/json'.

If respBody is non-nil and the response status is 200 OK or 201 Created, the response body is JSON-decoded into respBody.

opts are applied to the request before it is sent. Useful options are defined in this package.

func NewRequest

func NewRequest(ctx context.Context, method, u string, reqBody io.Reader, opts []RequestOption) (*http.Request, error)

NewRequest creates a new HTTP request with the given context, method, URL, and body, then applies any provided request options.

func UnexpectedStatusCode

func UnexpectedStatusCode(resp *http.Response) error

UnexpectedStatusCode returns an error describing an unexpected HTTP status code, including the request method and URL for context. The resp must be a client response because http.Response.Request is only populated on responses received by the client.

func WithJSONBody

func WithJSONBody(ctx context.Context, method, u string, reqBody any, opts []RequestOption) (*http.Request, error)

WithJSONBody creates a new HTTP request with the given body JSON-encoded as the request body.

Types

type RequestOption

type RequestOption func(req *http.Request)

RequestOption specifies an option to be applied to an outgoing HTTP request.

Callers may accept multiple RequestOptions as a variadic or slice parameter. Options must be applied to the request using Apply.

A RequestOption must be reusable and must not hold any per-request state.

func AcceptLanguage

func AcceptLanguage(tags []language.Tag) RequestOption

AcceptLanguage returns a internal.RequestOption that appends the given language tags to the 'Accept-Language' header on outgoing requests, preserving any tags already present in the header.

func ContractVersion

func ContractVersion(v string) RequestOption

ContractVersion returns a RequestOption that sets the X-Xbl-Contract-Version header to the specified version string. The appropriate version depends on the target endpoint. The value 'vnext' may also be accepted for some endpoint.

func RequestHeader

func RequestHeader(key, value string) RequestOption

RequestHeader returns a internal.RequestOption that sets a request header with the given name and value on outgoing requests.

Jump to

Keyboard shortcuts

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