Skip to content

Commit

Permalink
fix: join multiple header values by comma, not semicolon (#49)
Browse files Browse the repository at this point in the history
* fix(flattenHeadersObject): join multiple values by comma

* fix(flattenHeadersList): join multiple values by comma

* docs: update readme
  • Loading branch information
kettanaito authored Oct 9, 2022
1 parent 02a04d4 commit d020428
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ appendHeader(
import { flattenHeadersList } from 'headers-polyfill'
flattenHeadersList([['content-type', ['text/plain', 'image/png']]])
// ['content-type', 'text/plain; image/png']
// ['content-type', 'text/plain, image/png']
```

- `flattenHeadersObject: (o: Record<string, string | string[]>): Record<string, string>`
Expand All @@ -219,5 +219,5 @@ import { flattenHeadersObject } from 'headers-polyfill'
flattenHeadersObject({
'content-type': ['text/plain', 'image/png'],
})
// { 'content-type': 'text/plain; image/png' }
// { 'content-type': 'text/plain, image/png' }
```
2 changes: 1 addition & 1 deletion src/transformers/flattenHeadersList.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('given a headers list', () => {
]

expect(flattenHeadersList(headersList)).toEqual([
['accept', 'application/json; text/xml'],
['accept', 'application/json, text/xml'],
['content-type', 'application/pdf'],
])
})
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/flattenHeadersList.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import { HeadersList, FlatHeadersList } from '../glossary'

export function flattenHeadersList(list: HeadersList): FlatHeadersList {
return list.map(([name, values]) => {
return [name, ([] as string[]).concat(values).join('; ')]
return [name, ([] as string[]).concat(values).join(', ')]
})
}
2 changes: 1 addition & 1 deletion src/transformers/flattenHeadersObject.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('given a headers object', () => {
}

expect(flattenHeadersObject(headersObject)).toEqual({
Accept: 'application/json; text/xml',
Accept: 'application/json, text/xml',
'Content-Type': 'application/pdf',
})
})
Expand Down
2 changes: 1 addition & 1 deletion src/transformers/flattenHeadersObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function flattenHeadersObject(
return reduceHeadersObject<FlatHeadersObject>(
headersObject,
(headers, name, value) => {
headers[name] = ([] as string[]).concat(value).join('; ')
headers[name] = ([] as string[]).concat(value).join(', ')
return headers
},
{}
Expand Down

0 comments on commit d020428

Please sign in to comment.