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>2022-02-17 00:46:53 +0300
committerfeistel <6742251-feistel@users.noreply.gitlab.com>2022-02-17 00:46:53 +0300
commit661fb6a96638e3a6af3a0e23f309294ab11df789 (patch)
tree6346b0ce8431f7475ea2df85e0f353ec4047089b /internal
parentfba96f28a6d0d9af3810d9d996bf32654771eaca (diff)
refactor: use multierrors in custom headers parsing
Diffstat (limited to 'internal')
-rw-r--r--internal/customheaders/customheaders.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/internal/customheaders/customheaders.go b/internal/customheaders/customheaders.go
index 96662fe1..92f50069 100644
--- a/internal/customheaders/customheaders.go
+++ b/internal/customheaders/customheaders.go
@@ -7,6 +7,8 @@ import (
"net/http"
"net/textproto"
"strings"
+
+ "github.com/hashicorp/go-multierror"
)
var (
@@ -27,23 +29,28 @@ func AddCustomHeaders(w http.ResponseWriter, headers http.Header) {
func ParseHeaderString(customHeaders []string) (http.Header, error) {
headers := make(http.Header, len(customHeaders))
+ var result *multierror.Error
for _, h := range customHeaders {
h = h + "\n\n"
tp := textproto.NewReader(bufio.NewReader(strings.NewReader(h)))
mimeHeader, err := tp.ReadMIMEHeader()
if err != nil {
- return nil, fmt.Errorf("parsing error %s: %w", h, errInvalidHeaderParameter)
+ result = multierror.Append(result, fmt.Errorf("parsing error %s: %w", h, errInvalidHeaderParameter))
}
for key, value := range mimeHeader {
if _, ok := headers[key]; ok {
- return nil, fmt.Errorf("%s already specified with value '%s': %w", key, value, errDuplicateHeader)
+ result = multierror.Append(result, fmt.Errorf("%s already specified with value '%s': %w", key, value, errDuplicateHeader))
}
headers[key] = value
}
}
+ if result.ErrorOrNil() != nil {
+ return nil, result
+ }
+
return headers, nil
}