1
- import { roundNumber } from "../helpers/misc" ;
1
+ import { isInStatusCodeRange , roundNumber } from "../helpers/misc" ;
2
2
import { toInt } from "../helpers/parse" ;
3
3
import { Entry , Har , PageTimings } from "../typing/har" ;
4
4
import {
5
+ Icon ,
5
6
Mark ,
6
- RequestType ,
7
7
TimingType ,
8
8
WaterfallData ,
9
9
WaterfallDocs ,
10
10
WaterfallEntry ,
11
11
WaterfallEntryIndicator ,
12
12
WaterfallEntryTab ,
13
13
WaterfallEntryTiming ,
14
+ WaterfallResponseDetails ,
14
15
} from "../typing/waterfall" ;
16
+ import { makeIcon } from "../waterfall/row/svg-indicators" ;
15
17
import { collectIndicators , documentIsSecure } from "./har-heuristics" ;
16
18
import { makeTabs } from "./har-tabs" ;
17
19
import { mimeToRequestType } from "./helpers" ;
@@ -20,9 +22,7 @@ function createWaterfallEntry(url: string,
20
22
start : number ,
21
23
end : number ,
22
24
segments : WaterfallEntryTiming [ ] = [ ] ,
23
- rawResource : Entry ,
24
- requestType : RequestType ,
25
- indicators : WaterfallEntryIndicator [ ] ,
25
+ responseDetails : WaterfallResponseDetails ,
26
26
tabs : WaterfallEntryTab [ ] ) : WaterfallEntry {
27
27
const total = ( typeof start !== "number" || typeof end !== "number" ) ? undefined : ( end - start ) ;
28
28
return {
@@ -31,9 +31,7 @@ function createWaterfallEntry(url: string,
31
31
start,
32
32
end,
33
33
segments,
34
- rawResource,
35
- requestType,
36
- indicators,
34
+ responseDetails,
37
35
tabs,
38
36
} ;
39
37
}
@@ -77,13 +75,12 @@ function toWaterFallEntry(entry: Entry, index: number, startRelative: number, is
77
75
const endRelative = toInt ( entry . _all_end ) || ( startRelative + entry . time ) ;
78
76
const requestType = mimeToRequestType ( entry . response . content . mimeType ) ;
79
77
const indicators = collectIndicators ( entry , isTLS , requestType ) ;
78
+ const responseDetails = createResponseDetails ( entry , indicators ) ;
80
79
return createWaterfallEntry ( entry . request . url ,
81
80
startRelative ,
82
81
endRelative ,
83
82
buildDetailTimingBlocks ( startRelative , entry ) ,
84
- entry ,
85
- requestType ,
86
- indicators ,
83
+ responseDetails ,
87
84
makeTabs ( entry , ( index + 1 ) , requestType , startRelative , endRelative , indicators ) ,
88
85
) ;
89
86
}
@@ -199,3 +196,51 @@ function getTimePair(key: string, harEntry: Entry, collect: WaterfallEntryTiming
199
196
"start" : start ,
200
197
} ;
201
198
}
199
+
200
+ function createResponseDetails ( entry : Entry , indicators : WaterfallEntryIndicator [ ] ) : WaterfallResponseDetails {
201
+ const requestType = mimeToRequestType ( entry . response . content . mimeType ) ;
202
+
203
+ return {
204
+ icon : getMimeTypeIcon ( entry , requestType ) ,
205
+ rowClass : getRowCssClasses ( entry ) ,
206
+ indicators,
207
+ requestType,
208
+ statusCode : entry . response . status ,
209
+ } ;
210
+ }
211
+
212
+ /**
213
+ * Scan the request for errors or potential issues and highlight them
214
+ * @param {Entry } entry
215
+ * @returns {Icon }
216
+ */
217
+ function getMimeTypeIcon ( entry : Entry , requestType ) : Icon {
218
+ const status = entry . response . status ;
219
+ // highlight redirects
220
+ if ( ! ! entry . response . redirectURL ) {
221
+ const url = encodeURI ( entry . response . redirectURL . split ( "?" ) [ 0 ] || "" ) ;
222
+ return makeIcon ( "err3xx" , `${ status } response status: Redirect to ${ url } ...` ) ;
223
+ } else if ( isInStatusCodeRange ( status , 400 , 499 ) ) {
224
+ return makeIcon ( "err4xx" , `${ status } response status: ${ entry . response . statusText } ` ) ;
225
+ } else if ( isInStatusCodeRange ( status , 500 , 599 ) ) {
226
+ return makeIcon ( "err5xx" , `${ status } response status: ${ entry . response . statusText } ` ) ;
227
+ } else if ( status === 204 ) {
228
+ return makeIcon ( "plain" , "No content" ) ;
229
+ } else {
230
+ return makeIcon ( requestType , requestType ) ;
231
+ }
232
+ }
233
+
234
+ function getRowCssClasses ( entry : Entry ) : string {
235
+ const classes = [ "row-item" ] ;
236
+ if ( isInStatusCodeRange ( entry . response . status , 500 , 599 ) ) {
237
+ classes . push ( "status5xx" ) ;
238
+ } else if ( isInStatusCodeRange ( entry . response . status , 400 , 499 ) ) {
239
+ classes . push ( "status4xx" ) ;
240
+ } else if ( entry . response . status !== 304 &&
241
+ isInStatusCodeRange ( entry . response . status , 300 , 399 ) ) {
242
+ // 304 == Not Modified, so not an issue
243
+ classes . push ( "status3xx" ) ;
244
+ }
245
+ return classes . join ( " " ) ;
246
+ }
0 commit comments