Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-pages.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfeistel <6742251-feistel@users.noreply.gitlab.com>2021-07-08 12:31:16 +0300
committerfeistel <6742251-feistel@users.noreply.gitlab.com>2022-02-16 20:14:29 +0300
commit6b8e43cc39b38d7932061f7d8864c075eeb41934 (patch)
treee5af7d43dc402ec51f8d13ee9d757f73f7ad746d /internal
parentae8fbc5bf6725e6fa5b5a9dec6e4ac5016ec3c6c (diff)
refactor: parse custom headers using ReadMIMEHeader
Diffstat (limited to 'internal')
-rw-r--r--internal/customheaders/customheaders.go15
1 files changed, 9 insertions, 6 deletions
diff --git a/internal/customheaders/customheaders.go b/internal/customheaders/customheaders.go
index b54df585..f80d7f9a 100644
--- a/internal/customheaders/customheaders.go
+++ b/internal/customheaders/customheaders.go
@@ -1,8 +1,10 @@
package customheaders
import (
+ "bufio"
"errors"
"net/http"
+ "net/textproto"
"strings"
)
@@ -21,15 +23,16 @@ func AddCustomHeaders(w http.ResponseWriter, headers http.Header) {
func ParseHeaderString(customHeaders []string) (http.Header, error) {
headers := http.Header{}
for _, keyValueString := range customHeaders {
- keyValue := strings.SplitN(keyValueString, ":", 2)
- if len(keyValue) != 2 {
+ keyValueString = strings.TrimSpace(keyValueString) + "\n\n"
+ tp := textproto.NewReader(bufio.NewReader(strings.NewReader(keyValueString)))
+ keyValue, err := tp.ReadMIMEHeader()
+ if err != nil {
return nil, errInvalidHeaderParameter
}
- key := strings.TrimSpace(keyValue[0])
- value := strings.TrimSpace(keyValue[1])
-
- headers[key] = append(headers[key], value)
+ for k, v := range keyValue {
+ headers[k] = append(headers[k], v...)
+ }
}
return headers, nil
}