Skip to content

Commit

Permalink
Encode response bin headers (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
luborco authored Sep 2, 2024
1 parent b4a9b35 commit 5874274
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pkg/service/transformer/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package transformer

import (
"context"
"encoding/base64"
"net/http"
"strings"

Expand All @@ -22,6 +23,8 @@ const (
headerContentType = "content-type"
headerContentLength = "content-length"

headerBinarySuffix = "-bin"

// connection specific headers http1.0/1.1
headerConnection = "connection"
headerProxyConnection = "proxy-connection"
Expand Down Expand Up @@ -131,7 +134,14 @@ func setHeader(headers http.Header, protoMajor int, name string, values []string
if protoMajor > 1 && isConnectionSpecificHeader(name) {
return
}

// RFC 9113 8.2.1.: field values in HTTP prohibit some characters
isBinHeader := strings.HasSuffix(name, headerBinarySuffix)

for _, value := range values {
if isBinHeader {
value = base64.RawStdEncoding.EncodeToString([]byte(value))
}
headers.Add(name, value)
}
}

0 comments on commit 5874274

Please sign in to comment.