Skip to content

Commit af04f68

Browse files
authored
test(fromHar): add 304 response with body test case (#91)
1 parent 1645767 commit af04f68

File tree

2 files changed

+197
-0
lines changed

2 files changed

+197
-0
lines changed
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
{
2+
"log": {
3+
"version": "1.2",
4+
"creator": {
5+
"name": "WebInspector",
6+
"version": "537.36"
7+
},
8+
"pages": [],
9+
"entries": [
10+
{
11+
"_initiator": {
12+
"type": "script",
13+
"stack": {
14+
"callFrames": [
15+
{
16+
"functionName": "eval",
17+
"scriptId": "27",
18+
"url": "",
19+
"lineNumber": 3,
20+
"columnNumber": 39
21+
},
22+
{
23+
"functionName": "eval",
24+
"scriptId": "27",
25+
"url": "",
26+
"lineNumber": 1,
27+
"columnNumber": 56
28+
},
29+
{
30+
"functionName": "evaluate",
31+
"scriptId": "20",
32+
"url": "",
33+
"lineNumber": 340,
34+
"columnNumber": 15
35+
},
36+
{
37+
"functionName": "",
38+
"scriptId": "26",
39+
"url": "",
40+
"lineNumber": 0,
41+
"columnNumber": 43
42+
}
43+
]
44+
}
45+
},
46+
"_priority": "High",
47+
"_resourceType": "websocket",
48+
"cache": {},
49+
"connection": "29",
50+
"request": {
51+
"method": "GET",
52+
"url": "http://127.0.0.1:60906/redirect",
53+
"httpVersion": "HTTP/1.1",
54+
"headers": [
55+
{
56+
"name": "Host",
57+
"value": "127.0.0.1:60906"
58+
},
59+
{
60+
"name": "Connection",
61+
"value": "keep-alive"
62+
},
63+
{
64+
"name": "sec-ch-ua",
65+
"value": "\"Chromium\";v=\"93\", \" Not;A Brand\";v=\"99\""
66+
},
67+
{
68+
"name": "sec-ch-ua-mobile",
69+
"value": "?0"
70+
},
71+
{
72+
"name": "User-Agent",
73+
"value": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4576.0 Safari/537.36"
74+
},
75+
{
76+
"name": "sec-ch-ua-platform",
77+
"value": "\"macOS\""
78+
},
79+
{
80+
"name": "Accept",
81+
"value": "*/*"
82+
},
83+
{
84+
"name": "Origin",
85+
"value": "null"
86+
},
87+
{
88+
"name": "Sec-Fetch-Site",
89+
"value": "cross-site"
90+
},
91+
{
92+
"name": "Sec-Fetch-Mode",
93+
"value": "cors"
94+
},
95+
{
96+
"name": "Sec-Fetch-Dest",
97+
"value": "empty"
98+
},
99+
{
100+
"name": "Accept-Encoding",
101+
"value": "gzip, deflate, br"
102+
},
103+
{
104+
"name": "Accept-Language",
105+
"value": "en-US,en;q=0.9"
106+
}
107+
],
108+
"queryString": [],
109+
"cookies": [],
110+
"headersSize": 473,
111+
"bodySize": 0
112+
},
113+
"response": {
114+
"status": 304,
115+
"statusText": "",
116+
"httpVersion": "HTTP/1.1",
117+
"headers": [
118+
{
119+
"name": "X-Powered-By",
120+
"value": "Express"
121+
},
122+
{
123+
"name": "Access-Control-Allow-Origin",
124+
"value": "*"
125+
},
126+
{
127+
"name": "Content-Type",
128+
"value": "text/html; charset=utf-8"
129+
},
130+
{
131+
"name": "Content-Length",
132+
"value": "11"
133+
},
134+
{
135+
"name": "ETag",
136+
"value": "W/\"b-Kq5sNclPz7QV2+lfQIuc6R7oRu0\""
137+
},
138+
{
139+
"name": "Date",
140+
"value": "Thu, 12 Aug 2021 13:35:57 GMT"
141+
},
142+
{
143+
"name": "Connection",
144+
"value": "keep-alive"
145+
}
146+
],
147+
"cookies": [],
148+
"content": {
149+
"size": 11,
150+
"mimeType": "text/html",
151+
"compression": 0,
152+
"text": "hello world"
153+
},
154+
"redirectURL": "",
155+
"headersSize": 236,
156+
"bodySize": 11,
157+
"_transferSize": 247,
158+
"_error": null
159+
},
160+
"serverIPAddress": "127.0.0.1",
161+
"startedDateTime": "2021-08-12T13:35:57.824Z",
162+
"time": 9.306000000050409,
163+
"timings": {
164+
"blocked": 0.6450000005667098,
165+
"dns": 0.0050000000000000044,
166+
"ssl": -1,
167+
"connect": 0.157,
168+
"send": 0.08600000000000002,
169+
"wait": 8.125000000210829,
170+
"receive": 0.2879999992728699,
171+
"_blocked_queueing": 0.4960000005667098
172+
}
173+
}
174+
]
175+
}
176+
}

test/traffic/response-status.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,24 @@ it('supports non-configurable response status codes', async () => {
2525
},
2626
])
2727
})
28+
29+
it('supports a 304 responses with a body', async () => {
30+
const har = readArchive(
31+
'test/traffic/fixtures/archives/response-status-304.har',
32+
)
33+
const handlers = fromTraffic(har, normalizeLocalhost)
34+
expect(await inspectHandlers(handlers)).toEqual<InspectedHandler[]>([
35+
{
36+
handler: {
37+
method: 'GET',
38+
path: 'http://localhost/redirect',
39+
},
40+
response: {
41+
status: 304,
42+
statusText: '',
43+
headers: _toHeaders(har.log.entries[0].response.headers),
44+
body: '',
45+
},
46+
},
47+
])
48+
})

0 commit comments

Comments
 (0)