Skip to content

Commit

Permalink
fix: do not split headers by comma
Browse files Browse the repository at this point in the history
Reverts the core change in 9c7939e
Relates to #1031
Fixes #1058

chore: allow v4 tests to run without env var for contributors

chore: update debug message for headers

chore: update mocha test to use correct multi-valued header syntax
  • Loading branch information
mefellows committed Jul 8, 2023
1 parent bff5a44 commit 2e65324
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
20 changes: 8 additions & 12 deletions examples/mocha/test/get-dogs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,19 @@ describe('The Dog API', () => {
method: 'GET',
path: '/dogs',
headers: {
Accept:
'application/problem+json, application/json, text/plain, */*',
// Accept: [
// 'application/problem+json',
// 'application/json',
// 'text/plain',
// '*/*',
// ],
// Accept: 'application/problem+json, application/json, text/plain, */*', // <- fails, must use array syntax ❌
Accept: [
'application/problem+json',
'application/json',
'text/plain',
'*/*',
],
},
},
willRespondWith: {
status: 200,
headers: {
'Content-Type': Matchers.term({
generate: 'application/json',
matcher: 'application/json.*',
}),
'Content-Type': 'application/json',
},
body: EXPECTED_BODY,
},
Expand Down
5 changes: 1 addition & 4 deletions src/httpPact/ffi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,6 @@ export const setHeaders = (

if (Array.isArray(v)) {
values = v;
} else if (typeof v === 'string') {
// Allow comma separated items, such as: "application/problem+json, application/json, */*"
values = v.split(',').map((h) => h.trim());
} else {
values = [v];
}
Expand All @@ -104,7 +101,7 @@ export const setHeaders = (
case InteractionPart.REQUEST:
values.forEach((h, i) => {
logger.debug(
`setting header request value for ${h} at index ${i} to ${JSON.stringify(
`setting header request value for ${k} at index ${i} to ${JSON.stringify(
matcherValueOrString(h)
)}`
);
Expand Down
1 change: 1 addition & 0 deletions src/pact.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import chaiAsPromised from 'chai-as-promised';
import sinonChai from 'sinon-chai';
import axios from 'axios';
import net = require('net');

import { PactV4 } from './v4';

const { expect } = chai;
Expand Down

0 comments on commit 2e65324

Please sign in to comment.