Skip to content

Commit 352fb38

Browse files
committed
Hide HTTP/2 pseudo headers by default
1 parent 3d5218c commit 352fb38

File tree

6 files changed

+105
-34
lines changed

6 files changed

+105
-34
lines changed

src/components/send/response-pane.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export class ResponsePane extends React.Component<{
6666
/>
6767
<SentResponseHeaderSection
6868
{...this.cardProps.responseHeaders}
69+
httpVersion={exchange.httpVersion}
6970
requestUrl={exchange.request.parsedUrl}
7071
headers={response.rawHeaders}
7172
/>

src/components/send/sent-response-headers.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@ import { CollapsingButtons } from '../common/collapsing-buttons';
1717
import { ExpandShrinkButton } from '../common/expand-shrink-button';
1818

1919
export interface ResponseHeaderSectionProps extends ExpandableCardProps {
20+
httpVersion: 1 | 2;
2021
requestUrl: URL;
2122
headers: RawHeaders;
2223
}
2324

2425
export const SentResponseHeaderSection = ({
26+
httpVersion,
2527
requestUrl,
2628
headers,
2729
...cardProps
@@ -40,6 +42,7 @@ export const SentResponseHeaderSection = ({
4042
</header>
4143
<SendCardScrollableWrapper>
4244
<HeaderDetails
45+
httpVersion={httpVersion}
4346
requestUrl={requestUrl}
4447
headers={headers}
4548
/>

src/components/view/http/header-details.tsx

Lines changed: 80 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
5261
const getHeaderDescription = (
5362
name: string,
5463
value: string,
@@ -78,38 +87,80 @@ const getHeaderDescription = (
7887
};
7988

8089
export 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+
});

src/components/view/http/http-details-pane.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ export class HttpDetailsPane extends React.Component<{
312312
} else if (!!response) {
313313
cards.push(<HttpResponseCard
314314
{...this.cardProps.response}
315+
httpVersion={exchange.httpVersion}
315316
response={response}
316317
requestUrl={exchange.request.parsedUrl}
317318
apiExchange={apiExchange}

src/components/view/http/http-request-card.tsx

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ const MatchedRulePill = styled(inject('uiStore')((p: {
8888
}
8989
`;
9090

91-
const RawRequestDetails = (p: { request: HtkRequest }) => {
91+
const RawRequestDetails = (p: {
92+
request: HtkRequest,
93+
httpVersion: 1 | 2
94+
}) => {
9295
const methodDocs = getMethodDocs(p.request.method);
9396
const methodDetails = [
9497
methodDocs && <Markdown
@@ -134,7 +137,11 @@ const RawRequestDetails = (p: { request: HtkRequest }) => {
134137
</CollapsibleSection>
135138

136139
<ContentLabelBlock>Headers</ContentLabelBlock>
137-
<HeaderDetails headers={p.request.rawHeaders} requestUrl={p.request.parsedUrl} />
140+
<HeaderDetails
141+
httpVersion={p.httpVersion}
142+
headers={p.request.rawHeaders}
143+
requestUrl={p.request.parsedUrl}
144+
/>
138145
</div>;
139146
}
140147

@@ -179,6 +186,9 @@ export const HttpRequestCard = observer((props: HttpRequestCardProps) => {
179186
</CollapsibleCardHeading>
180187
</header>
181188

182-
<RawRequestDetails request={request} />
189+
<RawRequestDetails
190+
request={request}
191+
httpVersion={exchange.httpVersion}
192+
/>
183193
</CollapsibleCard>;
184194
});

src/components/view/http/http-response-card.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,14 @@ import { DocsLink } from '../../common/docs-link';
3434

3535
interface HttpResponseCardProps extends CollapsibleCardProps {
3636
theme: Theme;
37+
httpVersion: 1 | 2;
3738
requestUrl: URL;
3839
response: HtkResponse;
3940
apiExchange: ApiExchange | undefined;
4041
}
4142

4243
export const HttpResponseCard = observer((props: HttpResponseCardProps) => {
43-
const { response, requestUrl, theme, apiExchange } = props;
44+
const { httpVersion, response, requestUrl, theme, apiExchange } = props;
4445

4546
const apiResponseDescription = get(apiExchange, 'response', 'description');
4647
const statusDocs = getStatusDocs(response.statusCode);
@@ -86,7 +87,11 @@ export const HttpResponseCard = observer((props: HttpResponseCardProps) => {
8687
</CollapsibleSection>
8788

8889
<ContentLabelBlock>Headers</ContentLabelBlock>
89-
<HeaderDetails headers={response.rawHeaders} requestUrl={requestUrl} />
90+
<HeaderDetails
91+
httpVersion={httpVersion}
92+
headers={response.rawHeaders}
93+
requestUrl={requestUrl}
94+
/>
9095
</div>
9196
</CollapsibleCard>;
9297
});

0 commit comments

Comments
 (0)