Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 028fa77

Browse files
author
Barthélémy Ledoux
authoredJul 12, 2021
Merge branch 'develop' into runner-shared-misc
2 parents e58d2fd + c2a2206 commit 028fa77

File tree

6 files changed

+75
-62
lines changed

6 files changed

+75
-62
lines changed
 

‎.github/ISSUE_TEMPLATE/config.yml

+12-42
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,12 @@
1-
name: "🐛 Bug report"
2-
description: Report a bug found while using Cypress.
3-
body:
4-
- type: markdown
5-
attributes:
6-
value: |
7-
Have a question? 👉 [Start a new discussion](https://github.com/cypress-io/cypress/discussions) or [ask in chat](https://on.cypress.io/discord).
8-
- type: textarea
9-
id: current-behavior
10-
attributes:
11-
label: Current behavior
12-
description: A description including screenshots, stack traces, DEBUG logs, etc. [Troubleshooting tips](https://on.cypress.io/troubleshooting).
13-
placeholder: Currently...
14-
validations:
15-
required: true
16-
- type: textarea
17-
id: desired-behavior
18-
attributes:
19-
label: Desired behavior
20-
description: Remember, we're not familiar with the app you're testing, so please provide a clear description of what should happen.
21-
placeholder: In this situation, Cypress should...
22-
- type: textarea
23-
id: reproduction
24-
attributes:
25-
label: Test code to reproduce
26-
description: Provide a failing test or repo we can run. You can fork [this repo](https://github.com/cypress-io/cypress-test-tiny), set up a failing test, then link to your fork.
27-
placeholder: Here is my failing test code and the app code to run the tests on...
28-
validations:
29-
required: true
30-
- type: input
31-
id: version
32-
attributes:
33-
label: Cypress Version
34-
description: Run `cypress version` to see your current version. If possible, please update Cypress to the latest version first.
35-
placeholder: ex. 7.6.0
36-
validations:
37-
required: true
38-
- type: textarea
39-
id: othter
40-
attributes:
41-
label: Other
42-
placeholder: Any other details?
1+
blank_issues_enabled: false
2+
contact_links:
3+
- name: 🤔 Questions and Help
4+
url: https://github.com/cypress-io/cypress/discussions
5+
about: This issue tracker is not for support questions. Please refer to our Discussions.
6+
- name: 💬 Chat
7+
url: https://on.cypress.io/discord
8+
about: Want to discuss Cypress with others? Check out our chat.
9+
- name: 📃 Documentation Issue
10+
url: https://github.com/cypress-io/cypress-documentation/issues/new
11+
about: This issue tracker is not for documentation issues. Please open documentation issues here.
12+

‎packages/driver/cypress/integration/commands/net_stubbing_spec.ts

+24
Original file line numberDiff line numberDiff line change
@@ -2652,6 +2652,30 @@ describe('network stubbing', { retries: 2 }, function () {
26522652
.wait('@get')
26532653
})
26542654

2655+
// https://github.com/cypress-io/cypress/issues/17084
2656+
it('does not overwrite the json-related content-type header', () => {
2657+
cy.intercept('/json-content-type', (req) => {
2658+
req.on('response', (res) => {
2659+
res.send({
2660+
statusCode: 500,
2661+
headers: {
2662+
'content-type': 'application/problem+json',
2663+
'access-control-allow-origin': '*',
2664+
},
2665+
body: {
2666+
status: 500,
2667+
title: 'Internal Server Error',
2668+
},
2669+
})
2670+
})
2671+
})
2672+
2673+
fetch('/json-content-type')
2674+
.then((res) => {
2675+
expect(res.headers.get('content-type')).to.eq('application/problem+json')
2676+
})
2677+
})
2678+
26552679
context('body parsing', function () {
26562680
[
26572681
'application/json',

‎packages/driver/src/cy/net-stubbing/events/response.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,14 @@ export const onResponse: HandlerFn<CyHttpMessages.IncomingResponse> = async (Cyp
7575
// arguments to res.send() are merged with the existing response
7676
const _staticResponse = _.defaults({}, staticResponse, _.pick(res, STATIC_RESPONSE_KEYS))
7777

78-
_.defaults(_staticResponse.headers, res.headers)
78+
_staticResponse.headers = _.defaults({}, _staticResponse.headers, res.headers)
79+
80+
// https://github.com/cypress-io/cypress/issues/17084
81+
// When a user didn't provide content-type,
82+
// we remove the content-type provided by the server
83+
if (!staticResponse.headers || !staticResponse.headers['content-type']) {
84+
delete _staticResponse.headers['content-type']
85+
}
7986

8087
sendStaticResponse(requestId, _staticResponse)
8188

‎packages/driver/src/cy/net-stubbing/static-response-utils.ts

+13-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import {
55
BackendStaticResponseWithArrayBuffer,
66
FixtureOpts,
77
} from '@packages/net-stubbing/lib/types'
8+
import {
9+
caseInsensitiveHas,
10+
} from '@packages/net-stubbing/lib/util'
811
import $errUtils from '../../cypress/error_utils'
912

1013
// user-facing StaticResponse only
@@ -112,7 +115,16 @@ export function getBackendStaticResponse (staticResponse: Readonly<StaticRespons
112115
backendStaticResponse.body = staticResponse.body
113116
} else {
114117
backendStaticResponse.body = JSON.stringify(staticResponse.body)
115-
_.set(backendStaticResponse, 'headers.content-type', 'application/json')
118+
119+
// There are various json-related MIME types. We cannot simply set it as `application/json`.
120+
// @see https://www.iana.org/assignments/media-types/media-types.xhtml
121+
if (
122+
!backendStaticResponse.headers ||
123+
(backendStaticResponse.headers &&
124+
!caseInsensitiveHas(backendStaticResponse.headers, 'content-type'))
125+
) {
126+
_.set(backendStaticResponse, 'headers.content-type', 'application/json')
127+
}
116128
}
117129
}
118130

‎packages/net-stubbing/lib/server/util.ts

+1-18
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import ThrottleStream from 'throttle'
1616
import MimeTypes from 'mime-types'
1717
import { CypressIncomingRequest } from '@packages/proxy'
1818
import { InterceptedRequest } from './intercepted-request'
19+
import { caseInsensitiveGet, caseInsensitiveHas } from '../util'
1920

2021
// TODO: move this into net-stubbing once cy.route is removed
2122
import { parseContentType } from '@packages/server/lib/controllers/xhrs'
@@ -79,24 +80,6 @@ function _getFakeClientResponse (opts: {
7980
return clientResponse
8081
}
8182

82-
const caseInsensitiveGet = function (obj, lowercaseProperty) {
83-
for (let key of Object.keys(obj)) {
84-
if (key.toLowerCase() === lowercaseProperty) {
85-
return obj[key]
86-
}
87-
}
88-
}
89-
90-
const caseInsensitiveHas = function (obj, lowercaseProperty) {
91-
for (let key of Object.keys(obj)) {
92-
if (key.toLowerCase() === lowercaseProperty) {
93-
return true
94-
}
95-
}
96-
97-
return false
98-
}
99-
10083
export function setDefaultHeaders (req: CypressIncomingRequest, res: IncomingMessage) {
10184
const setDefaultHeader = (lowercaseHeader: string, defaultValueFn: () => string) => {
10285
if (!caseInsensitiveHas(res.headers, lowercaseHeader)) {

‎packages/net-stubbing/lib/util.ts

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
export const caseInsensitiveGet = function (obj, lowercaseProperty) {
2+
for (let key of Object.keys(obj)) {
3+
if (key.toLowerCase() === lowercaseProperty) {
4+
return obj[key]
5+
}
6+
}
7+
}
8+
9+
export const caseInsensitiveHas = function (obj, lowercaseProperty) {
10+
for (let key of Object.keys(obj)) {
11+
if (key.toLowerCase() === lowercaseProperty) {
12+
return true
13+
}
14+
}
15+
16+
return false
17+
}

0 commit comments

Comments
 (0)
Please sign in to comment.