README

gentleman/cookies Build Status GoDoc Go Report Card

gentleman's plugin to easily deal and manage cookies HTTP clients.

Installation

go get -u gopkg.in/h2non/gentleman.v2/plugins/cookies

API

See godoc reference.

Example

package main

import (
  "fmt"
  "gopkg.in/h2non/gentleman.v2"
  "gopkg.in/h2non/gentleman.v2/plugins/cookies"
)

func main() {
  // Create a new client
  cli := gentleman.New()

  // Define cookies
  cli.Use(cookies.Set("foo", "bar"))

  // Configure cookie jar store
  cli.Use(cookies.Jar())

  // Perform the request
  res, err := cli.Request().URL("http://httpbin.org/cookies").Send()
  if err != nil {
    fmt.Printf("Request error: %s\n", err)
    return
  }
  if !res.Ok {
    fmt.Printf("Invalid server response: %d\n", res.StatusCode)
    return
  }

  fmt.Printf("Status: %d\n", res.StatusCode)
  fmt.Printf("Body: %s", res.String())
}

License

MIT - Tomas Aparicio

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Add

func Add(cookie *http.Cookie) p.Plugin

    Add adds a cookie to the request. Per RFC 6265 section 5.4, AddCookie does not attach more than one Cookie header field. That means all cookies, if any, are written into the same line, separated by semicolon.

    func AddMultiple

    func AddMultiple(cookies []*http.Cookie) p.Plugin

      AddMultiple adds a list of cookies.

      func DelAll

      func DelAll() p.Plugin

        DelAll deletes all the cookies by deleting the Cookie header field.

        func Jar

        func Jar() p.Plugin

          Jar creates a cookie jar to store HTTP cookies when they are sent down.

          func Set

          func Set(key, value string) p.Plugin

            Set sets a new cookie field by key and value.

            func SetMap

            func SetMap(cookies map[string]string) p.Plugin

              SetMap sets a map of cookies represented by key-value pair.

              Types

              This section is empty.

              Source Files