cookiedisk

package module
v0.0.0-...-f666ebb Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2020 License: MIT Imports: 10 Imported by: 0

README

CookieDisk

cookiedisk is Go package to use Netscape cookie file format (e.g, cookie.txt).

Build Status GoDoc

Example

import(
	"net/http"
	"net/http/cookiejar"
	"net/http/url"

	"github.com/kosh04/cookiedisk"
)

rawURL := "http://httpbin.org/cookies"
cookies, _ := cookiedisk.ReadFile("./data/cookie.txt")
u, _ := url.Parse(rawURL)
jar, _ := cookiejar.New(rawURL)
jar.SetCookies(u, cookies)
client := http.Client{Jar: jar}
resp, err := client.Get(rawURL)
...

Issue

  • Can interconversion between http.Cookie and NetscapeCookieFormat ?

TODO

  • maintenance test
  • complete main.go options

License

MIT License

Documentation

Overview

Package cookiedisk provides to use Netscape cookie file format (cookie.txt).

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Read

func Read(r io.Reader) []*http.Cookie

Read cookies from stream

func ReadFile

func ReadFile(filename string) ([]*http.Cookie, error)

ReadFile read cookies from file

Example
package main

import (
	"fmt"
	"io/ioutil"
	"log"
	"net/http"
	"net/http/cookiejar"
	"net/url"

	"github.com/kosh04/cookiedisk"
)

func main() {
	rawURL := "http://httpbin.org/cookies"
	cookies, _ := cookiedisk.ReadFile("testdata/cookie.txt")
	u, _ := url.Parse(rawURL)
	jar, _ := cookiejar.New(nil)
	jar.SetCookies(u, cookies)
	client := http.Client{Jar: jar}
	resp, err := client.Get(rawURL)
	if err != nil {
		log.Fatal(err)
	}
	defer resp.Body.Close()
	body, _ := ioutil.ReadAll(resp.Body)

	fmt.Println(string(body))
}
Output:

{
  "cookies": {
    "k1": "v1"
  }
}

func WriteFile

func WriteFile(filename string, u *url.URL, cookies []*http.Cookie) error

WriteFile write cookies to filename

Types

type Entry

type Entry struct {
	Domain    domain
	TailMatch bool // weather we do tail-matchning of the domain name
	Path      string
	Secure    bool
	Expires   time.Time
	Name      string
	Value     string
}

Entry is Netscape cookie format see also: CURL/lib/cookie.c:get_netscape_format()

func NewEntry

func NewEntry(u url.URL, c http.Cookie) *Entry

NewEntry creates Netscape cookie entry from http.Cookie

func (Entry) String

func (e Entry) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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