TUN-2880: Return metadata about source of the response from cloudflared

This commit is contained in:
Areg Harutyunyan
2020-04-09 21:59:15 +01:00
parent a37da2b165
commit 322f909edb
4 changed files with 36 additions and 6 deletions

View File

@@ -2,6 +2,7 @@ package h2mux
import (
"encoding/base64"
"encoding/json"
"fmt"
"net/http"
"net/url"
@@ -20,6 +21,10 @@ var headerEncoding = base64.RawStdEncoding
const (
RequestUserHeadersField = "cf-cloudflared-request-headers"
ResponseUserHeadersField = "cf-cloudflared-response-headers"
ResponseMetaHeaderField = "cf-cloudflared-response-meta"
ResponseSourceCloudflared = "cloudflared"
ResponseSourceOrigin = "origin"
)
// H2RequestHeadersToH1Request converts the HTTP/2 headers coming from origintunneld
@@ -226,3 +231,19 @@ func CreateSerializedHeaders(headersField string, headers ...http.Header) []Head
strings.Join(serializedHeaderChunks, ";"),
}}
}
type responseMetaHeader struct {
Source string `json:"src"`
}
func CreateResponseMetaHeader(source string) Header {
jsonResponseMetaHeader, err := json.Marshal(responseMetaHeader{Source: source})
if err != nil {
panic(err)
}
return Header{
Name: ResponseMetaHeaderField,
Value: string(jsonResponseMetaHeader),
}
}