~emersion/drmdb

94921e53caa90181569e71943c4d7e5351aedd59 — Simon Ser 4 months ago 8a09ed1
Parse the Forwarded header, if any
1 files changed, 16 insertions(+), 1 deletions(-)

M server.go
M server.go => server.go +16 -1
@@ 4,6 4,7 @@ import (
	"encoding/json"
	"fmt"
	"io"
	"mime"
	"net/http"
	"os"
	"sort"


@@ 55,6 56,16 @@ func loadPCIIDs() (vendors map[uint16]string, devices map[uint32]string, err err
	return vendors, devices, db.Close()
}

func parseForwarded(h http.Header) map[string]string {
	forwarded := h.Get("Forwarded")
	if forwarded == "" {
		return nil
	}
	// Hack to easily parse parameters
	_, params, _ := mime.ParseMediaType("hack; " + forwarded)
	return params
}

func New() *echo.Echo {
	e := echo.New()



@@ 90,7 101,11 @@ func New() *echo.Echo {
			NumDrivers   int
		}{}

		data.Host = c.Request().Host
		if forwarded := parseForwarded(c.Request().Header); forwarded["host"] != "" {
			data.Host = forwarded["host"]
		} else {
			data.Host = c.Request().Host
		}

		devices := make(map[string]struct{})
		drivers := make(map[string]struct{})