spacecookies

package
v0.0.0-...-6b6e1e4 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2023 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package spacecookies implements support for HTTP cookies with a space in their name. Go does not support it https://github.com/golang/go/issues/11519.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Transport

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

Transport implements a RoundTripper adding space cookies support to an existing RoundTripper.

func New

func New(transport http.RoundTripper, jar http.CookieJar) *Transport

New wraps around a Transport and a Cookie Jar to support cookies with space in the name. Just like an http.Client if transport is nil, http.DefaultTransport is used.

Example
jar, err := cookiejar.New(nil)
if err != nil {
	log.Fatal(err)
}
client := http.DefaultClient
client.Jar = jar

// Wrap around the client's transport to add support for space cookies.
client.Transport = New(client.Transport, jar)

// Assuming example.com sets space cookies, they get added to the jar.
resp, err := client.Get("https://example.com")
if err != nil {
	log.Fatal(err)
}
defer resp.Body.Close()

// So that following requests carry these cookies.
resp, err = client.Get("https://example.com")
if err != nil {
	log.Fatal(err)
}
defer resp.Body.Close()
Output:

func (*Transport) RoundTrip

func (t *Transport) RoundTrip(req *http.Request) (*http.Response, error)

RoundTrip executes a single HTTP transaction to add support for space cookies. It is safe for concurrent use by multiple goroutines.

Jump to

Keyboard shortcuts

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