Skip to content

superfly/flysrc-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

flysrc-go

flysrc-go is a go module providing support for parsing Fly-Src headers in Fly.io Machines, as described in https://community.fly.io/t/fly-src-authenticating-http-requests-between-fly-apps/20566 and https://community.fly.io/t/more-fly-src-authenticating-http-requests-between-fly-apps/26147.

Example

The following shows how an http server could use the library to get the fly-src information:

type FlySrcServer struct {
	parser *flysrc.Parser
}

func (serv *FlySrcServer) handleFlySrc(w http.ResponseWriter, req *http.Request) {
	src, err := serv.parser.FromRequest(req)
	if err != nil {
		http.Error(w, err.Error(), http.StatusBadRequest)
		return
	}

	fmt.Fprintf(w, "peer: %v\n", req.RemoteAddr)
	fmt.Fprintf(w, "fly-src: %v\n", req.Header.Get("fly-src"))
	fmt.Fprintf(w, "fly-src-signature: %v\n", req.Header.Get("fly-src-signature"))
	fmt.Fprintf(w, "%+v\n", src)
}

func main() {
	parser, err := flysrc.New()
	if err != nil {
		fmt.Printf("cant build flysrc parser: %v\n", err)
		return
	}

	serv := FlySrcServer{parser}
	http.HandleFunc("/flysrc", serv.handleFlySrc)
	log.Fatal(http.ListenAndServe(":8080", nil))
}

About

A golang parser for Fly-Src headers in Fly.io Machines.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages