@@ -49,6 +49,15 @@ const HeaderDocsLink = styled(DocsLink)`
4949 margin-top: 10px;
5050` ;
5151
52+ const PseudoHeadersHiddenMessage = styled . span `
53+ grid-column: 2 / -1;
54+ font-style: italic;
55+ ` ;
56+
57+ const PseudoHeadersContent = styled ( CollapsibleSectionBody ) `
58+ line-height: 1.3;
59+ ` ;
60+
5261const getHeaderDescription = (
5362 name : string ,
5463 value : string ,
@@ -78,38 +87,80 @@ const getHeaderDescription = (
7887} ;
7988
8089export const HeaderDetails = inject ( 'accountStore' ) ( observer ( ( props : {
90+ httpVersion : 1 | 2 ;
8191 headers : RawHeaders ,
8292 requestUrl : URL ,
8393 accountStore ?: AccountStore
8494} ) => {
8595 const sortedHeaders = _ . sortBy ( props . headers , ( [ key ] ) => key . toLowerCase ( ) ) ;
8696
87- return sortedHeaders . length === 0 ?
88- < BlankContentPlaceholder > (None)</ BlankContentPlaceholder >
89- :
90- < HeadersGrid >
91- { _ . flatMap ( sortedHeaders , ( [ key , value ] , i ) => {
92- const docs = getHeaderDocs ( key ) ;
93- const description = getHeaderDescription (
94- key ,
95- value ,
96- props . requestUrl ,
97- props . accountStore ! . isPaidUser
98- )
99-
100- return < CollapsibleSection withinGrid = { true } key = { `${ key } -${ i } ` } >
101- < HeaderKeyValue >
102- < HeaderName > { key } : </ HeaderName >
103- < span > { value } </ span >
104- </ HeaderKeyValue >
105-
106- { description && < HeaderDescriptionContainer >
107- { description }
108- { docs && < HeaderDocsLink href = { docs . url } >
109- Find out more
110- </ HeaderDocsLink > }
111- </ HeaderDescriptionContainer > }
112- </ CollapsibleSection >
113- } ) }
114- </ HeadersGrid > ;
115- } ) ) ;
97+ if ( sortedHeaders . length === 0 ) {
98+ return < BlankContentPlaceholder > (None)</ BlankContentPlaceholder >
99+ }
100+
101+ let [ pseudoHeaders , normalHeaders ] = _ . partition ( sortedHeaders , ( [ key ] ) =>
102+ props . httpVersion >= 2 && key . startsWith ( ':' )
103+ ) ;
104+
105+ if ( normalHeaders . length === 0 ) {
106+ normalHeaders = pseudoHeaders ;
107+ pseudoHeaders = [ ] ;
108+ }
109+
110+ return < HeadersGrid >
111+ {
112+ pseudoHeaders . length > 0 && < CollapsibleSection withinGrid = { true } >
113+ < CollapsibleSectionSummary >
114+ < PseudoHeadersHiddenMessage >
115+ HTTP/{ props . httpVersion } pseudo-headers
116+ </ PseudoHeadersHiddenMessage >
117+ </ CollapsibleSectionSummary >
118+
119+ < PseudoHeadersContent >
120+ < PseudoHeaderDetails
121+ headers = { pseudoHeaders }
122+ />
123+ </ PseudoHeadersContent >
124+ </ CollapsibleSection >
125+ }
126+
127+ { _ . flatMap ( normalHeaders , ( [ key , value ] , i ) => {
128+ const docs = getHeaderDocs ( key ) ;
129+ const description = getHeaderDescription (
130+ key ,
131+ value ,
132+ props . requestUrl ,
133+ props . accountStore ! . isPaidUser
134+ )
135+
136+ return < CollapsibleSection withinGrid = { true } key = { `${ key } -${ i } ` } >
137+ < HeaderKeyValue >
138+ < HeaderName > { key } : </ HeaderName >
139+ < span > { value } </ span >
140+ </ HeaderKeyValue >
141+
142+ { description && < HeaderDescriptionContainer >
143+ { description }
144+ { docs && < HeaderDocsLink href = { docs . url } >
145+ Find out more
146+ </ HeaderDocsLink > }
147+ </ HeaderDescriptionContainer > }
148+ </ CollapsibleSection > ;
149+ } ) }
150+ </ HeadersGrid > ;
151+ } ) ) ;
152+
153+ const PseudoHeaderDetails = observer ( ( props : {
154+ headers : RawHeaders
155+ } ) => {
156+ return < HeadersGrid >
157+ { _ . flatMap ( props . headers , ( [ key , value ] , i ) => {
158+ return < CollapsibleSection withinGrid = { true } key = { `${ key } -${ i } ` } >
159+ < HeaderKeyValue >
160+ < HeaderName > { key } : </ HeaderName >
161+ < span > { value } </ span >
162+ </ HeaderKeyValue >
163+ </ CollapsibleSection > ;
164+ } ) }
165+ </ HeadersGrid > ;
166+ } ) ;
0 commit comments