header

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2021 License: MIT Imports: 3 Imported by: 0

README

header

Package header sets header for the http.ResponseWriter.

Get started

Install
go get github.com/hslam/handler
Import
import "github.com/hslam/handler"
Usage
Example
package main

import (
	"github.com/hslam/handler/header"
	"github.com/hslam/mux"
	"log"
	"net/http"
)

func main() {
	m := mux.New()
	m.Use(func(w http.ResponseWriter, r *http.Request) {
		header.SetHeader(w, header.AccessControlAllowOrigin, "*")
	})
	m.HandleFunc("/hello", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("Hello World"))
	}).All()
	log.Fatal(http.ListenAndServe(":8080", m))
}

curl -I http://localhost:8080/hello

HTTP/1.1 200 OK
Access-Control-Allow-Origin: *
Date: Sun, 06 Oct 2019 15:58:02 GMT
Content-Length: 11
Content-Type: text/plain; charset=utf-8
License

This package is licensed under a MIT license (Copyright (c) 2019 Meng Huang)

Author

header was written by Meng Huang.

Documentation

Index

Constants

View Source
const (
	ContentEncoding = "Content-Encoding"
	ContentLanguage = "Content-Language"
	ContentLength   = "Content-Length"
	ContentLocation = "Content-Location"
	ContentMD5      = "Content-MD5"
	ContentRange    = "Content-Range"
	ContentType     = "Content-Type"

	AcceptRanges = "Accept-Ranges"
	Bytes        = "bytes"

	AcceptEncoding = "Accept-Encoding"
	GZIP           = "gzip"
	DEFLATE        = "deflate"

	Vary          = "Vary"
	Charset       = "charset"
	CharsetPrefix = "charset="
	UTF8          = "UTF-8"
	GB18030       = "GB18030"
	GBK           = "GBK"

	Semicolon = ";"
	Comma     = ","

	ContentTypeJSON = "application/json"
	ContentTypeXML  = "text/xml"
	ContentTypeHTML = "text/html"
	ContentTypeText = "text/plain"

	AccessControlAllowOrigin      = "Access-Control-Allow-Origin"
	AccessControlAllowCredentials = "Access-Control-Allow-Credentials"
	AccessControlMaxAge           = "Access-Control-Max-Age"
	AccessControlAllowMethods     = "Access-Control-Allow-Methods"
	AccessControlAllowHeaders     = "Access-Control-Allow-Headers"
)

Variables

This section is empty.

Functions

func AllowCredentials

func AllowCredentials(w http.ResponseWriter)

func AllowHeaders

func AllowHeaders(w http.ResponseWriter, Headers ...string)

func AllowMethods

func AllowMethods(w http.ResponseWriter, Methods ...string)

func AllowOrigin

func AllowOrigin(w http.ResponseWriter, value string)

func AllowOriginAll

func AllowOriginAll(w http.ResponseWriter)

func CheckAcceptEncoding

func CheckAcceptEncoding(r *http.Request, compressType string) bool

func DelHeader

func DelHeader(w http.ResponseWriter, key string)

func GetRequestHeader

func GetRequestHeader(r *http.Request, key string) (value string)

func GetResponseHeader

func GetResponseHeader(w http.ResponseWriter, key string) (value string)

func MaxAge

func MaxAge(w http.ResponseWriter, age int)

func SetCharset

func SetCharset(w http.ResponseWriter, charset string)

func SetContentEncoding

func SetContentEncoding(w http.ResponseWriter, compressType string)

func SetContentLength

func SetContentLength(w http.ResponseWriter, length int)

func SetContentType

func SetContentType(w http.ResponseWriter, value string)

func SetContentTypeWithCharset

func SetContentTypeWithCharset(w http.ResponseWriter, value string, charset string)

func SetHeader

func SetHeader(w http.ResponseWriter, key, value string)

func WriteHeader

func WriteHeader(w http.ResponseWriter, code int)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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