// HTTP/Minimal Reference Server // A compliant server implementation for the HTTP/Minimal specification. // // Usage: // go run main.go -dir ./content -port 8080 // // The server will: // - Serve Markdown files from the content directory // - Content-negotiate between text/markdown and text/html // - Strip raw HTML from Markdown before serving // - Validate and enforce HTTP/Minimal constraints // - Serve /.well-known/http-minimal policy endpoint package main import ( "bytes" "encoding/json" "flag" "fmt" "html/template" "io" "log" "mime" "net/http" "os" "path/filepath" "regexp" "strings" "github.com/yuin/goldmark" "github.com/yuin/goldmark/extension" "github.com/yuin/goldmark/parser" "github.com/yuin/goldmark/renderer/html" "gopkg.in/yaml.v3" ) // Config holds server configuration type Config struct { Port string ContentDir string TemplateFile string BaseURL string Contact string } // FrontMatter represents YAML front matter in Markdown documents type FrontMatter struct { Title string `yaml:"title"` Author string `yaml:"author"` Date string `yaml:"date"` Lang string `yaml:"lang"` License string `yaml:"license"` Description string `yaml:"description"` } // WellKnown represents the /.well-known/http-minimal response type WellKnown struct { HTTPMinimal string `json:"http_minimal"` Compliant bool `json:"compliant"` Scope string `json:"scope"` Contact string `json:"contact,omitempty"` } // Server implements an HTTP/Minimal compliant server type Server struct { config Config markdown goldmark.Markdown htmlTmpl *template.Template } // defaultHTMLTemplate is the built-in fallback template for rendering Markdown to browsers const defaultHTMLTemplate = `