Skip to content

Commit

Permalink
chore: release 0.5.2 (#208)
Browse files Browse the repository at this point in the history
* chore: release 0.5.2
* fix: normalize headers with multiple vals
  • Loading branch information
lidel authored May 20, 2024
1 parent cf3d1bf commit 26994cf
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
- 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)
## [0.5.2] - 2024-05-20
### Changed
- Fixed: relaxed dag-cbor error check ([#205](https://github.com/ipfs/gateway-conformance/pull/205))
- Fixed: Header().Has works properly for checking multiple values ([#207](https://github.com/ipfs/gateway-conformance/pull/207))

## [0.5.1] - 2024-04-11
- Removed byte range text for DAG-CBOR objects converted to `text/html`. [PR](https://github.com/ipfs/gateway-conformance/pull/202)
Expand Down
23 changes: 23 additions & 0 deletions tooling/test/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"io"
"net/http"
"strings"
"testing"

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

for _, header := range expected.Headers_ {
testName := fmt.Sprintf("Header %s", header.Key_)

actual := res.Header.Values(header.Key_)

// HTTP Headers can have multiple values, and that can be represented by comman separated value,
// or sending the same header more than once. The `res.Header.Get` only returns the value
// from the first header, so we use Values here.
// At the same time, we don't want to have two separate checks everywhere, so we normalize
// multiple instances of the same header by converting it into a single one, with comma-separated
// values.
if len(actual) > 1 {
var result []string
all := strings.Join(actual, ",")
split := strings.Split(all, ",")
for _, s := range split {
value := strings.TrimSpace(s)
if value != "" {
result = append(result, strings.TrimSpace(s))
}
}
// Normalize values from all instances of the header into a single one and comma-separated notation
joined := strings.Join(result, ", ")
actual = []string{joined}
}

c := header.Check_
if header.Not_ {
c = check.Not(c)
Expand Down

0 comments on commit 26994cf

Please sign in to comment.