Skip to content

Commit 26994cf

Browse files
authored
chore: release 0.5.2 (#208)
* chore: release 0.5.2 * fix: normalize headers with multiple vals
1 parent cf3d1bf commit 26994cf

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7-
## [Unreleased]
8-
- Relaxed the DAG-CBOR error check: we no longer check the body of the response, only the status code. [PR](https://github.com/ipfs/gateway-conformance/pull/205)
7+
## [0.5.2] - 2024-05-20
8+
### Changed
9+
- Fixed: relaxed dag-cbor error check ([#205](https://github.com/ipfs/gateway-conformance/pull/205))
10+
- Fixed: Header().Has works properly for checking multiple values ([#207](https://github.com/ipfs/gateway-conformance/pull/207))
911

1012
## [0.5.1] - 2024-04-11
1113
- Removed byte range text for DAG-CBOR objects converted to `text/html`. [PR](https://github.com/ipfs/gateway-conformance/pull/202)

tooling/test/validate.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"io"
77
"net/http"
8+
"strings"
89
"testing"
910

1011
"github.com/ipfs/gateway-conformance/tooling/check"
@@ -42,8 +43,30 @@ func validateResponse(
4243

4344
for _, header := range expected.Headers_ {
4445
testName := fmt.Sprintf("Header %s", header.Key_)
46+
4547
actual := res.Header.Values(header.Key_)
4648

49+
// HTTP Headers can have multiple values, and that can be represented by comman separated value,
50+
// or sending the same header more than once. The `res.Header.Get` only returns the value
51+
// from the first header, so we use Values here.
52+
// At the same time, we don't want to have two separate checks everywhere, so we normalize
53+
// multiple instances of the same header by converting it into a single one, with comma-separated
54+
// values.
55+
if len(actual) > 1 {
56+
var result []string
57+
all := strings.Join(actual, ",")
58+
split := strings.Split(all, ",")
59+
for _, s := range split {
60+
value := strings.TrimSpace(s)
61+
if value != "" {
62+
result = append(result, strings.TrimSpace(s))
63+
}
64+
}
65+
// Normalize values from all instances of the header into a single one and comma-separated notation
66+
joined := strings.Join(result, ", ")
67+
actual = []string{joined}
68+
}
69+
4770
c := header.Check_
4871
if header.Not_ {
4972
c = check.Not(c)

0 commit comments

Comments
 (0)