Skip to content

Commit 517a2f8

Browse files
committed
Extract header methods & regex into a separate util
This notably tweaks the regex _slightly_ too, escaping the | because it turns out (recent change?) Chrome rejects it, since the current value isn't compatible with the 'v' flag it now uses in input pattern matching.
1 parent c0b03e6 commit 517a2f8

File tree

16 files changed

+68
-53
lines changed

16 files changed

+68
-53
lines changed

src/components/common/editable-headers.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import * as React from 'react';
33
import { observer } from 'mobx-react';
44

55
import { Headers } from '../../types';
6-
import { HEADER_NAME_PATTERN } from '../../model/http/http-docs';
6+
import { HEADER_NAME_PATTERN } from '../../util/headers';
77

88
import { EditablePairs, Pair, PairsArray } from './editable-pairs';
99

src/components/mock/handler-config.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
stringToBuffer,
1717
bufferToString
1818
} from '../../util';
19+
import { HEADER_NAME_REGEX } from '../../util/headers';
1920

2021
import {
2122
Handler,
@@ -74,7 +75,7 @@ import {
7475
SendStepDefinition
7576
} from '../../model/rules/definitions/rtc-rule-definitions';
7677

77-
import { getStatusMessage, HEADER_NAME_REGEX } from '../../model/http/http-docs';
78+
import { getStatusMessage } from '../../model/http/http-docs';
7879
import { MethodName, MethodNames } from '../../model/http/methods';
7980
import { NATIVE_ETH_TYPES } from '../../model/rules/definitions/ethereum-abi';
8081
import {

src/components/mock/matcher-config.tsx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { css, styled } from '../../styles';
1111

1212
import { tryParseJson } from '../../util';
1313
import { asError, UnreachableCheck } from '../../util/error';
14+
import { headersToFlatHeaders } from '../../util/headers';
1415

1516
import {
1617
Matcher,
@@ -22,6 +23,7 @@ import {
2223
getRulePartKey,
2324
isHiddenMatcherKey
2425
} from "../../model/rules/rules";
26+
import { summarizeMatcherClass } from '../../model/rules/rule-descriptions';
2527
import {
2628
WebSocketMethodMatcher
2729
} from '../../model/rules/definitions/websocket-rule-definitions';
@@ -49,7 +51,6 @@ import { Select, TextInput } from '../common/inputs';
4951
import { EditablePairs, PairsArray } from '../common/editable-pairs';
5052
import { EditableHeaders } from '../common/editable-headers';
5153
import { ThemedSelfSizedEditor } from '../editor/base-editor';
52-
import { summarizeMatcherClass } from '../../model/rules/rule-descriptions';
5354

5455
type MatcherConfigProps<M extends Matcher> = {
5556
matcher?: M;
@@ -778,18 +779,6 @@ class ExactQueryMatcherConfig extends MatcherConfig<matchers.ExactQueryMatcher>
778779
}
779780
}
780781

781-
type FlatHeaders = { [key: string]: string };
782-
783-
const headersToFlatHeaders = (headers: Headers): FlatHeaders =>
784-
_.mapValues(
785-
_.pickBy(headers, (key, value) => key && value),
786-
(value) =>
787-
_.isArray(value)
788-
? value.join(', ')
789-
: value! // We know this is set because of filter above
790-
);
791-
792-
793782
@observer
794783
class HeaderMatcherConfig extends MatcherConfig<matchers.HeaderMatcher> {
795784

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import { ExchangeMessage, HtkResponse, HtkRequest } from '../../../types';
99
import { styled } from '../../../styles';
1010
import { WarningIcon } from '../../../icons';
1111

12-
import { lastHeader } from '../../../util';
13-
import { saveFile } from '../../../util/ui';
1412
import { ErrorLike } from '../../../util/error';
13+
import { lastHeader } from '../../../util/headers';
14+
import { saveFile } from '../../../util/ui';
1515

1616
import { ViewableContentType, getCompatibleTypes, getContentEditorName } from '../../../model/events/content-types';
1717
import { getReadableSize } from '../../../model/events/bodies';

src/components/view/http/http-breakpoint-body-card.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import * as portals from 'react-reverse-portal';
66

77
import { Headers } from '../../../types';
88
import {
9-
lastHeader,
109
isProbablyUtf8,
1110
bufferToString,
1211
stringToBuffer
1312
} from '../../../util';
13+
import { lastHeader } from '../../../util/headers';
1414
import {
1515
EditableContentType,
1616
EditableContentTypes,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
TimingEvents,
1111
ExchangeMessage
1212
} from '../../../types';
13-
import { asHeaderArray } from '../../../util';
13+
import { asHeaderArray } from '../../../util/headers';
1414
import { joinAnd } from '../../../util/text';
1515
import { Icon, WarningIcon, SuggestionIcon } from '../../../icons';
1616

src/model/api/openapi.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ import {
2020
HtkResponse,
2121
Html
2222
} from "../../types";
23-
import { firstMatch, empty, lastHeader } from '../../util';
23+
import { firstMatch, empty } from '../../util';
24+
import { lastHeader } from '../../util/headers';
2425
import { formatAjvError } from '../../util/json-schema';
2526

2627
import {

src/model/events/categorization.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import * as _ from 'lodash';
22

33
import { ExchangeMessage } from '../../types';
4-
import { lastHeader } from '../../util';
54
import { Theme } from '../../styles';
5+
import { lastHeader } from '../../util/headers';
66

77
import { getBaseContentType } from './content-types';
88

src/model/http/caching.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
} from 'date-fns';
99

1010
import { HttpExchange, ExchangeMessage } from '../../types';
11-
import { lastHeader, asHeaderArray } from '../../util';
11+
import { lastHeader, asHeaderArray } from '../../util/headers';
1212
import { joinAnd } from '../../util/text';
1313

1414
// https://tools.ietf.org/html/draft-ietf-httpbis-semantics-04#section-7.2.3

src/model/http/editable-body.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { computed, observable, action, runInAction, reaction } from 'mobx';
33

44
import { BreakpointBody } from '../../types';
55
import { logError } from "../../errors";
6-
import { asHeaderArray } from "../../util";
6+
import { asHeaderArray } from "../../util/headers";
77
import { observablePromise, ObservablePromise } from '../../util/observable';
88

99
import { encodeBody } from "../../services/ui-worker-api";

0 commit comments

Comments
 (0)