A http client session for Go
Go to file
2013-09-10 15:58:47 +08:00
csession.go init project 2013-09-10 15:34:50 +08:00
doc.go init project 2013-09-10 15:34:50 +08:00
README.md doc improved 2013-09-10 15:58:47 +08:00

csession

Csession provides a client session for http client. It has the same methods as http.Client, but it will automatically save cookies, headers and set referer. This project has part codes from github.com/chzyer/go-fetcher.

Installing csession

go get github.com/lunny/csession

Quick Start

1.Before use please New or NewSession

import (
	"github.com/lunny/csession"
)
session := csession.New()

or

import (
	"github.com/lunny/csession"
)
session := csession.NewSession(transport, checkRedirect, jar)

NewSession's params are the same as http.Client's fields

2.If you want to customize your headers, your can set HeadersFunc as your func. Default, session.HeadersFunc = session.DefaultHeadersFunc.

session.HeadersFunc = func(req *http.Request) {
	session.DefaultHeadersFunc(req)
	req.Header.Set("Cache-Control", "max-age=0")
}

3.use session like use client

resp, err := session.Get("http://www.google.com")

forms := url.Values{
		"username": {"username"}, "password": {"password"},
	}


resp, err := session.PostForm("http://www.google.com", forms)

resp, err := session.Post("http://www.google.com")

resp, err := session.Head(...)

resp, err := sesion.Do(req)

Documents

Please visit GoWalker

LICENSE

BSD License http://creativecommons.org/licenses/BSD/