cors

package module
v0.0.0-...-0c2aae3 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2014 License: Apache-2.0 Imports: 5 Imported by: 3 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

cors

wercker status

Negroni middleware/handler to enable CORS support.

Usage

package main

import (
	"net/http"

	"github.com/codegangsta/negroni"
	"github.com/hariharan-uno/cors"
)

func main() {
	n := negroni.Classic()

	// CORS for https://*.foo.com origins, allowing:
	// - GET and POST methods
	// - Origin header
	options := cors.Options{
		AllowOrigins: []string{"https://*.foo.com"},
		AllowMethods: []string{"GET", "POST"},
		AllowHeaders: []string{"Origin"},
	}

	n.Use(negroni.HandlerFunc(options.Allow))

	mux := http.NewServeMux()
	// map your routes

	n.UseHandler(mux)

	n.Run(":3000")
}

###Documentation

Godoc

Authors

Documentation

Overview

Package cors provides handlers to enable CORS support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Options

type Options struct {
	// If set, all origins are allowed.
	AllowAllOrigins bool
	// A list of allowed origins. Wild cards and FQDNs are supported.
	AllowOrigins []string
	// If set, allows to share auth credentials such as cookies.
	AllowCredentials bool
	// A list of allowed HTTP methods.
	AllowMethods []string
	// A list of allowed HTTP headers.
	AllowHeaders []string
	// A list of exposed HTTP headers.
	ExposeHeaders []string
	// Max age of the CORS headers.
	MaxAge time.Duration
}

Options represents Access Control options.

func (*Options) Allow

func (o *Options) Allow(res http.ResponseWriter, req *http.Request, next http.HandlerFunc)

Allow enables CORS for requests those match the provided options.

func (*Options) Header

func (o *Options) Header(origin string) (headers map[string]string)

Header converts options into CORS headers.

func (*Options) IsOriginAllowed

func (o *Options) IsOriginAllowed(origin string) (allowed bool)

IsOriginAllowed looks up if the origin matches one of the patterns generated from Options.AllowOrigins patterns.

func (*Options) PreflightHeader

func (o *Options) PreflightHeader(origin, rMethod, rHeaders string) (headers map[string]string)

PreflightHeader converts options into CORS headers for a preflight response.

Jump to

Keyboard shortcuts

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