Skip to content

Commit 2fdcab7

Browse files
committed
Add some last small fixes/tweaks for gRPC compression change
1 parent 3d713b3 commit 2fdcab7

File tree

6 files changed

+24
-17
lines changed

6 files changed

+24
-17
lines changed

src/components/editor/content-viewer.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { styled } from '../../styles';
1010
import { ObservablePromise, isObservablePromise } from '../../util/observable';
1111
import { asError, unreachableCheck } from '../../util/error';
1212
import { stringToBuffer } from '../../util/buffer';
13+
import { lastHeader } from '../../util/headers';
1314

1415
import { ViewableContentType } from '../../model/events/content-types';
1516
import { Formatters, isEditorFormatter } from '../../model/events/body-formatting';
@@ -200,7 +201,7 @@ export class ContentViewer extends React.Component<ContentViewerProps> {
200201
return <FormatterContainer expanded={this.props.expanded}>
201202
<formatterConfig.Component
202203
content={this.contentBuffer}
203-
headers={this.props.headers}
204+
rawContentType={lastHeader(this.props.headers?.['content-type'])}
204205
/>
205206
</FormatterContainer>;
206207
}

src/components/intercept/config/android-device-config.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,10 @@ const Spacer = styled.div`
6464
`;
6565

6666
function urlSafeBase64(content: string) {
67-
return stringToBuffer(content).toString('base64url');
67+
return stringToBuffer(content)
68+
.toString('base64')
69+
.replace(/\+/g, '-')
70+
.replace(/\//g, '_');
6871
}
6972

7073
function getConfigRequestIds(eventsStore: EventsStore) {

src/model/events/body-formatting.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export interface EditorFormatter {
1919

2020
type FormatComponentProps = {
2121
content: Buffer;
22-
headers?: Headers;
22+
rawContentType: string | undefined;
2323
};
2424

2525
type FormatComponent = React.ComponentType<FormatComponentProps>;
@@ -65,7 +65,7 @@ export const Formatters: { [key in ViewableContentType]: Formatter } = {
6565
language: 'text',
6666
cacheKey: Symbol('text'),
6767
isEditApplicable: false,
68-
render: (input: Buffer, headers?: Headers) => {
68+
render: (input: Buffer) => {
6969
return bufferToString(input);
7070
}
7171
},
@@ -112,7 +112,9 @@ export const Formatters: { [key in ViewableContentType]: Formatter } = {
112112
// showing the loading spinner that churns the layout in short content cases.
113113
return JSON.stringify(
114114
JSON.parse(inputAsString),
115-
null, 2);
115+
null,
116+
2
117+
);
116118
// ^ Same logic as in UI-worker-formatter
117119
} catch (e) {
118120
// Fallback to showing the raw un-formatted JSON:

src/model/events/content-types.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export function getDefaultMimeType(contentType: ViewableContentType): string {
153153
return _.findKey(mimeTypeToContentTypeMap, (c) => c === contentType)!;
154154
}
155155

156-
function isValidAlphaNumOrSpace(byte: number) {
156+
function isAlphaNumOrEquals(byte: number) {
157157
return (byte >= 65 && byte <= 90) || // A-Z
158158
(byte >= 97 && byte <= 122) || // a-z
159159
(byte >= 48 && byte <= 57) || // 0-9
@@ -162,14 +162,16 @@ function isValidAlphaNumOrSpace(byte: number) {
162162

163163
function isValidStandardBase64Byte(byte: number) {
164164
// + / (standard)
165-
return byte === 43 || byte === 47
166-
|| isValidAlphaNumOrSpace(byte);
165+
return byte === 43 ||
166+
byte === 47 ||
167+
isAlphaNumOrEquals(byte);
167168
}
168169

169170
function isValidURLSafeBase64Byte(byte: number) {
170171
// - _ (URL-safe version)
171-
return byte === 45 || byte === 95
172-
|| isValidAlphaNumOrSpace(byte);
172+
return byte === 45 ||
173+
byte === 95 ||
174+
isAlphaNumOrEquals(byte);
173175
}
174176

175177
export function getCompatibleTypes(

src/model/http/har.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ export type RequestContentData = {
5757

5858
export interface ExtendedHarRequest extends HarFormat.Request {
5959
_requestBodyStatus?:
60-
| 'discarded:too-large'
61-
| 'discarded:not-representable' // to indicate that extended field `_content` is populated with base64 `postData`
62-
| 'discarded:not-decodable';
60+
| 'discarded:too-large'
61+
| 'discarded:not-representable' // to indicate that extended field `_content` is populated with base64 `postData`
62+
| 'discarded:not-decodable';
6363
_content?: RequestContentData;
6464
_trailers?: HarFormat.Header[];
6565
}
@@ -435,10 +435,10 @@ function generateHarWebSocketMessage(
435435
return {
436436
// Note that msg.direction is from the perspective of Mockttp, not the client.
437437
type: message.direction === 'sent'
438-
? 'receive'
438+
? 'receive'
439439
: message.direction === 'received'
440440
? 'send'
441-
: unreachableCheck(message.direction),
441+
: unreachableCheck(message.direction),
442442

443443
opcode: message.isBinary ? 2 : 1,
444444
data: message.isBinary

src/services/ui-worker-formatters.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ const WorkerFormatters = {
5656
},
5757
base64: (content: Buffer) => {
5858
const b64 = content.toString('ascii');
59-
const encoding = b64.match(/[-_]/) ? 'base64url' : 'base64';
60-
return Buffer.from(b64, encoding).toString('utf8');
59+
return Buffer.from(b64, 'base64').toString('utf8');
6160
},
6261
markdown: (content: Buffer) => {
6362
return content.toString('utf8');

0 commit comments

Comments
 (0)