1
0
Fork 0
No description
Find a file
Daniel Baumann fb76186cf2
Releasing fastforward version 1.1.1-2~ffwd13+u1.
Signed-off-by: Daniel Baumann <daniel@debian.org>
2026-03-13 06:00:31 +01:00
debian Releasing fastforward version 1.1.1-2~ffwd13+u1. 2026-03-13 06:00:31 +01:00
go.mod Adding upstream version 1.1.1. 2026-03-13 05:59:44 +01:00
headers.go Adding upstream version 1.1.1. 2026-03-13 05:59:44 +01:00
headers_test.go Adding upstream version 1.1.1. 2026-03-13 05:59:44 +01:00
LICENSE.txt Adding upstream version 1.1.1. 2026-03-13 05:59:44 +01:00
README.md Adding upstream version 1.1.1. 2026-03-13 05:59:44 +01:00

Go _headers parser

Headers format parser to match Netlify's _headers file format, plus a compatible unparser.

Example

package main

import (
    "encoding/json"
    "fmt"

    "codeberg.org/git-pages/go-headers"
)

func main() {
    rules := headers.Must(headers.ParseString(`
# enable COOP/COEP on index:
/index.html
  cross-origin-opener-policy: same-origin
  # breaks some use cases
  cross-origin-embedder-policy: credentialless
# on the worker too:
/worker.js
  cross-origin-embedder-policy: credentialless
/*
  x-content-type-options: nosniff
`))
    data, _ := json.MarshalIndent(rules, "", "  ")
    fmt.Printf("%s", data)
}
[
  {
    "Path": "/index.html",
    "Headers": {
      "Cross-Origin-Embedder-Policy": [
        "credentialless"
      ],
      "Cross-Origin-Opener-Policy": [
        "same-origin"
      ]
    }
  },
  {
    "Path": "/worker.js",
    "Headers": {
      "Cross-Origin-Embedder-Policy": [
        "credentialless"
      ]
    }
  },
  {
    "Path": "/*",
    "Headers": {
      "X-Content-Type-Options": [
        "nosniff"
      ]
    }
  }
]

License

0-clause BSD