2020-10-16 10:13:48 +00:00
|
|
|
package connection
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/cloudflare/cloudflared/h2mux"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2020-11-18 16:51:03 +00:00
|
|
|
ResponseMetaHeaderField = "cf-cloudflared-response-meta"
|
2020-10-16 10:13:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
canonicalResponseUserHeadersField = http.CanonicalHeaderKey(h2mux.ResponseUserHeadersField)
|
2020-11-18 16:51:03 +00:00
|
|
|
canonicalResponseMetaHeaderField = http.CanonicalHeaderKey(ResponseMetaHeaderField)
|
2020-10-20 15:26:55 +00:00
|
|
|
responseMetaHeaderCfd = mustInitRespMetaHeader("cloudflared")
|
|
|
|
responseMetaHeaderOrigin = mustInitRespMetaHeader("origin")
|
2020-10-16 10:13:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type responseMetaHeader struct {
|
|
|
|
Source string `json:"src"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func mustInitRespMetaHeader(src string) string {
|
|
|
|
header, err := json.Marshal(responseMetaHeader{Source: src})
|
|
|
|
if err != nil {
|
2020-10-23 14:49:24 +00:00
|
|
|
panic(fmt.Sprintf("Failed to serialize response meta header = %s, err: %v", src, err))
|
2020-10-16 10:13:48 +00:00
|
|
|
}
|
|
|
|
return string(header)
|
|
|
|
}
|