cors

package
v0.0.0-...-8ce6181 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2014 License: MIT Imports: 5 Imported by: 1

README

cors

Martini middleware/handler to enable CORS support.

Usage

import (
  "github.com/codegangsta/martini"
  "github.com/codegangsta/martini-contrib/cors"
)

func main() {
  m := martini.Classic()
  // CORS for https://foo.* origins, allowing:
  // - PUT and PATCH methods
  // - Origin header
  // - Credentials share
  m.Use(cors.Allow(&cors.Options{
    AllowOrigins:     []string{"https://foo\\.*"},
    AllowMethods:     []string{"PUT", "PATCH"},
    AllowHeaders:     []string{"Origin"},
    ExposeHeaders:    []string{"Content-Length"},
    AllowCredentials: true,
  }))
  m.Run()
}

Authors

Documentation

Overview

Package cors provides handlers to enable CORS support.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Allow

func Allow(opts *Options) http.HandlerFunc

Allows CORS for requests those match the provided options.

Types

type Options

type Options struct {
	// If set, all origins are allowed.
	AllowAllOrigins bool
	// A list of allowed domain patterns.
	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
}

Represents Access Control options.

func (*Options) Header

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

Converts options into CORS headers.

func (*Options) IsOriginAllowed

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

Looks up if the origin matches one of the patterns provided in Options.AllowOrigins patterns.

func (*Options) PreflightHeader

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

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