headers

package module
v0.0.0-...-bca4b57 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: MIT Imports: 5 Imported by: 6

README

Header

Header format parser to match Netlify's format.

Example

/*
  X-Frame-Options: DENY
  X-XSS-Protection: 1; mode=block

## A path:
/templates/index.html
  # Headers for that path:
  X-Frame-Options: DENY
  X-XSS-Protection: 1; mode=block

/templates/index2.html
  X-Frame-Options: SAMEORIGIN

yields

{
  "/*": {
    "X-Frame-Options": [
      "DENY"
    ],
    "X-Xss-Protection": [
      "1; mode=block"
    ]
  },
  "/templates/index.html": {
    "X-Frame-Options": [
      "DENY"
    ],
    "X-Xss-Protection": [
      "1; mode=block"
    ]
  },
  "/templates/index2.html": {
    "X-Frame-Options": [
      "SAMEORIGIN"
    ]
  }
}

GoDoc

Documentation

Overview

Package headers provides Netlify style _headers file format parsing.

Example
h := headers.Must(headers.ParseString(`
		/*
		  X-Frame-Options: DENY
		  X-XSS-Protection: 1; mode=block

		## A path:
		/templates/index.html
		  # Headers for that path:
		  X-Frame-Options: DENY
		  X-XSS-Protection: 1; mode=block

		/templates/index2.html
		  X-Frame-Options: SAMEORIGIN

		/*
		  Link: </style.css>; rel=preload; as=stylesheet
		  Link: </main.js>; rel=preload; as=script
		  Link: </image.jpg>; rel=preload; as=image
  `))

enc := json.NewEncoder(os.Stdout)
enc.SetIndent("", "  ")
enc.Encode(h)
Output:

{
  "/*": {
    "Link": [
      "\u003c/style.css\u003e; rel=preload; as=stylesheet",
      "\u003c/main.js\u003e; rel=preload; as=script",
      "\u003c/image.jpg\u003e; rel=preload; as=image"
    ],
    "X-Frame-Options": [
      "DENY"
    ],
    "X-Xss-Protection": [
      "1; mode=block"
    ]
  },
  "/templates/index.html": {
    "X-Frame-Options": [
      "DENY"
    ],
    "X-Xss-Protection": [
      "1; mode=block"
    ]
  },
  "/templates/index2.html": {
    "X-Frame-Options": [
      "SAMEORIGIN"
    ]
  }
}

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Must

func Must(m map[string]http.Header, err error) map[string]http.Header

Must parse utility.

func Parse

func Parse(r io.Reader) (map[string]http.Header, error)

Parse the given reader.

func ParseString

func ParseString(s string) (map[string]http.Header, error)

ParseString parses the given string.

Types

This section is empty.

Jump to

Keyboard shortcuts

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