cookiejar

package module
v0.0.0-...-114449e Latest Latest
Warning

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

Go to latest
Published: Jul 19, 2019 License: Apache-2.0 Imports: 18 Imported by: 0

README

CookieJar

A cookiejar drive with Go.

996.icu LICENSE

Example

package main

import (
	"fmt"
	"net/http"
	"io/ioutil"
	"github.com/telanflow/cookiejar"
)

func main() {

	// Netscape HTTP Cookie File
	jar, _ = cookiejar.NewFileJar("cookie.txt", nil)

	client := &http.Client{
		Jar: jar,
	}

	req, _ := http.NewRequest(http.MethodGet, "https://telan.me", nil)
	resp, err := client.Do(req)
	if err != nil {
		fmt.Println(err.Error())
		return
	}
	defer resp.Body.Close()

	c, _ := ioutil.ReadAll(resp.Body)
	fmt.Println(string(c))
}

Documentation

Overview

Package cookiejar implements an in-memory RFC 6265-compliant http.CookieJar.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewEntriesJar

func NewEntriesJar(o *Options) (http.CookieJar, error)

func NewFileJar

func NewFileJar(filename string, o *Options) (http.CookieJar, error)

func NewRedisJar

func NewRedisJar(namespaces string, pool *redis.Pool, o *Options) (http.CookieJar, error)

Types

type EntriesDrive

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

func (*EntriesDrive) Delete

func (e *EntriesDrive) Delete(key string)

func (*EntriesDrive) Get

func (e *EntriesDrive) Get(key string) map[string]entry

func (*EntriesDrive) Set

func (e *EntriesDrive) Set(key string, val map[string]entry)

type FileDrive

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

func (*FileDrive) Delete

func (f *FileDrive) Delete(key string)

func (*FileDrive) Get

func (f *FileDrive) Get(key string) map[string]entry

func (*FileDrive) Set

func (f *FileDrive) Set(key string, val map[string]entry)

type Jar

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

Jar implements the http.CookieJar interface from the net/http package.

func New

func New(s Storage, o *Options) (*Jar, error)

New returns a new cookie jar. A nil *Options is equivalent to a zero Options.

func (*Jar) Cookies

func (j *Jar) Cookies(u *url.URL) (cookies []*http.Cookie)

Cookies implements the Cookies method of the http.CookieJar interface.

It returns an empty slice if the URL's scheme is not HTTP or HTTPS.

func (*Jar) SetCookies

func (j *Jar) SetCookies(u *url.URL, cookies []*http.Cookie)

SetCookies implements the SetCookies method of the http.CookieJar interface.

It does nothing if the URL's s`cheme is not HTTP or HTTPS.

type Options

type Options struct {
	// PublicSuffixList is the public suffix list that determines whether
	// an HTTP server can set a cookie for a domain.
	//
	// A nil value is valid and may be useful for testing but it is not
	// secure: it means that the HTTP server for foo.co.uk can set a cookie
	// for bar.co.uk.
	PublicSuffixList PublicSuffixList
}

Options are the options for creating a new Jar.

type PublicSuffixList

type PublicSuffixList interface {
	// PublicSuffix returns the public suffix of domain.
	//
	// TODO: specify which of the caller and callee is responsible for IP
	// addresses, for leading and trailing dots, for case sensitivity, and
	// for IDN/Punycode.
	PublicSuffix(domain string) string

	// String returns a description of the source of this public suffix
	// list. The description will typically contain something like a time
	// stamp or version number.
	String() string
}

PublicSuffixList provides the public suffix of a domain. For example:

  • the public suffix of "example.com" is "com",
  • the public suffix of "foo1.foo2.foo3.co.uk" is "co.uk", and
  • the public suffix of "bar.pvt.k12.ma.us" is "pvt.k12.ma.us".

Implementations of PublicSuffixList must be safe for concurrent use by multiple goroutines.

An implementation that always returns "" is valid and may be useful for testing but it is not secure: it means that the HTTP server for foo.com can set a cookie for bar.com.

A public suffix list implementation is in the package golang.org/x/net/publicsuffix.

type RedisDrive

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

func (*RedisDrive) Delete

func (r *RedisDrive) Delete(key string)

func (*RedisDrive) Get

func (r *RedisDrive) Get(key string) map[string]entry

func (*RedisDrive) Set

func (r *RedisDrive) Set(key string, val map[string]entry)

type Storage

type Storage interface {
	Set(string, map[string]entry)
	Get(string) map[string]entry
	Delete(string)
}

Jump to

Keyboard shortcuts

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