context

package
v0.0.0-...-eea8398 Latest Latest
Warning

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

Go to latest
Published: May 7, 2016 License: Apache-2.0 Imports: 29 Imported by: 0

Documentation

Overview

Package context provide the context utils Usage:

	import "github.com/cooleo/goweb/context"

	ctx := context.Context{Request:req,ResponseWriter:rw}

 more docs http://goweb.me/docs/module/context.md

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewInput

func NewInput() *gowebInput

NewInput return gowebInput generated by Context.

func NewOutput

func NewOutput() *gowebOutput

NewOutput returns new gowebOutput. it contains nothing now.

func ParseEncoding

func ParseEncoding(r *http.Request) string

ParseEncoding will extract the right encoding for response the Accept-Encoding's sec is here: http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3

func WriteBody

func WriteBody(encoding string, writer io.Writer, content []byte) (bool, string, error)

WriteBody reads writes content to writer by the specific encoding(gzip/deflate)

func WriteFile

func WriteFile(encoding string, writer io.Writer, file *os.File) (bool, string, error)

WriteFile reads from file and writes to writer by the specific encoding(gzip/deflate)

Types

type Context

type Context struct {
	Input          *gowebInput
	Output         *gowebOutput
	Request        *http.Request
	ResponseWriter *Response
	// contains filtered or unexported fields
}

Context Http request context struct including gowebInput, gowebOutput, http.Request and http.ResponseWriter. gowebInput and gowebOutput provides some api to operate request and response more easily.

func NewContext

func NewContext() *Context

NewContext return the Context with Input and Output

func (*Context) Abort

func (ctx *Context) Abort(status int, body string)

Abort stops this request. if goweb.ErrorMaps exists, panic body.

func (*Context) CheckXSRFCookie

func (ctx *Context) CheckXSRFCookie() bool

CheckXSRFCookie checks xsrf token in this request is valid or not. the token can provided in request header "X-Xsrftoken" and "X-CsrfToken" or in form field value named as "_xsrf".

func (*Context) GetCookie

func (ctx *Context) GetCookie(key string) string

GetCookie Get cookie from request by a given key. It's alias of gowebInput.Cookie.

func (*Context) GetSecureCookie

func (ctx *Context) GetSecureCookie(Secret, key string) (string, bool)

GetSecureCookie Get secure cookie from request by a given key.

func (*Context) Redirect

func (ctx *Context) Redirect(status int, localurl string)

Redirect does redirection to localurl with http header status code. It sends http response header directly.

func (*Context) Reset

func (ctx *Context) Reset(rw http.ResponseWriter, r *http.Request)

Reset init Context, gowebInput and gowebOutput

func (*Context) SetCookie

func (ctx *Context) SetCookie(name string, value string, others ...interface{})

SetCookie Set cookie for response. It's alias of gowebOutput.Cookie.

func (*Context) SetSecureCookie

func (ctx *Context) SetSecureCookie(Secret, name, value string, others ...interface{})

SetSecureCookie Set Secure cookie for response.

func (*Context) WriteString

func (ctx *Context) WriteString(content string)

WriteString Write string to response body. it sends response body.

func (*Context) XSRFToken

func (ctx *Context) XSRFToken(key string, expire int64) string

XSRFToken creates a xsrf token string and returns.

type Response

type Response struct {
	http.ResponseWriter
	Started bool
	Status  int
}

Response is a wrapper for the http.ResponseWriter started set to true if response was written to then don't execute other handler

func (*Response) CloseNotify

func (r *Response) CloseNotify() <-chan bool

CloseNotify http.CloseNotifier

func (*Response) Copy

func (r *Response) Copy(buf *bytes.Buffer) (int64, error)

Copy writes the data to the connection as part of an HTTP reply, and sets `started` to true. started means the response has sent out.

func (*Response) Flush

func (r *Response) Flush()

Flush http.Flusher

func (*Response) Hijack

func (r *Response) Hijack() (net.Conn, *bufio.ReadWriter, error)

Hijack hijacker for http

func (*Response) Write

func (r *Response) Write(p []byte) (int, error)

Write writes the data to the connection as part of an HTTP reply, and sets `started` to true. started means the response has sent out.

func (*Response) WriteHeader

func (r *Response) WriteHeader(code int)

WriteHeader sends an HTTP response header with status code, and sets `started` to true.

Jump to

Keyboard shortcuts

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