Repository navigation
Expand file tree
/
Copy pathconfigurationSettings.ts
More file actions
448 lines (363 loc) · 16.2 KB
/
Copy pathconfigurationSettings.ts
File metadata and controls
448 lines (363 loc) · 16.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
import { CharacterPair, Event, EventEmitter, languages, ViewColumn, window, workspace } from 'vscode';
import configuration from '../../language-configuration.json';
import { getCurrentTextDocument } from '../utils/workspaceUtility';
import { RequestHeaders } from './base';
import { FormParamEncodingStrategy, fromString as ParseFormParamEncodingStr } from './formParamEncodingStrategy';
import { fromString as ParseLogLevelStr, LogLevel } from './logLevel';
import { fromString as ParsePreviewOptionStr, PreviewOption } from './previewOption';
import { RequestMetadata } from './requestMetadata';
export type HostCertificates = {
[key: string]: {
cert?: string;
key?: string;
pfx?: string;
passphrase?: string;
}
};
export interface IRestClientSettings {
readonly followRedirect: boolean;
readonly defaultHeaders: RequestHeaders;
readonly timeoutInMilliseconds: number;
readonly showResponseInDifferentTab: boolean;
readonly requestNameAsResponseTabTitle: boolean;
readonly proxy?: string;
readonly proxyStrictSSL: boolean;
readonly rememberCookiesForSubsequentRequests: boolean;
readonly enableTelemetry: boolean;
readonly excludeHostsForProxy: string[];
readonly fontSize?: number;
readonly fontFamily?: string;
readonly fontWeight?: string;
readonly environmentVariables: { [key: string]: { [key: string]: string } };
readonly mimeAndFileExtensionMapping: { [key: string]: string };
readonly previewResponseInUntitledDocument: boolean;
readonly hostCertificates: HostCertificates;
readonly suppressResponseBodyContentTypeValidationWarning: boolean;
readonly previewOption: PreviewOption;
readonly disableHighlightResonseBodyForLargeResponse: boolean;
readonly disableAddingHrefLinkForLargeResponse: boolean;
readonly largeResponseBodySizeLimitInMB: number;
readonly previewColumn: ViewColumn;
readonly previewResponsePanelTakeFocus: boolean;
readonly formParamEncodingStrategy: FormParamEncodingStrategy;
readonly addRequestBodyLineIndentationAroundBrackets: boolean;
readonly decodeEscapedUnicodeCharacters: boolean;
readonly logLevel: LogLevel;
readonly enableSendRequestCodeLens: boolean;
readonly enableCustomVariableReferencesCodeLens: boolean;
readonly useContentDispositionFilename: boolean;
}
export class SystemSettings implements IRestClientSettings {
private _followRedirect: boolean;
private _defaultHeaders: RequestHeaders;
private _timeoutInMilliseconds: number;
private _showResponseInDifferentTab: boolean;
private _requestNameAsResponseTabTitle: boolean;
private _proxy?: string;
private _proxyStrictSSL: boolean;
private _rememberCookiesForSubsequentRequests: boolean;
private _enableTelemetry: boolean;
private _excludeHostsForProxy: string[];
private _fontSize?: number;
private _fontFamily?: string;
private _fontWeight?: string;
private _environmentVariables: { [key: string]: { [key: string]: string } };
private _mimeAndFileExtensionMapping: { [key: string]: string };
private _previewResponseInUntitledDocument: boolean;
private _hostCertificates: HostCertificates;
private _suppressResponseBodyContentTypeValidationWarning: boolean;
private _previewOption: PreviewOption;
private _disableHighlightResonseBodyForLargeResponse: boolean;
private _disableAddingHrefLinkForLargeResponse: boolean;
private _largeResponseBodySizeLimitInMB: number;
private _previewColumn: ViewColumn;
private _previewResponsePanelTakeFocus: boolean;
private _formParamEncodingStrategy: FormParamEncodingStrategy;
private _addRequestBodyLineIndentationAroundBrackets: boolean;
private _decodeEscapedUnicodeCharacters: boolean;
private _logLevel: LogLevel;
private _enableSendRequestCodeLens: boolean;
private _enableCustomVariableReferencesCodeLens: boolean;
private _useContentDispositionFilename: boolean;
public get followRedirect() {
return this._followRedirect;
}
public get defaultHeaders() {
return this._defaultHeaders;
}
public get timeoutInMilliseconds() {
return this._timeoutInMilliseconds;
}
public get showResponseInDifferentTab() {
return this._showResponseInDifferentTab;
}
public get requestNameAsResponseTabTitle() {
return this._requestNameAsResponseTabTitle;
}
public get proxy() {
return this._proxy;
}
public get proxyStrictSSL() {
return this._proxyStrictSSL;
}
public get rememberCookiesForSubsequentRequests() {
return this._rememberCookiesForSubsequentRequests;
}
public get enableTelemetry() {
return this._enableTelemetry;
}
public get excludeHostsForProxy() {
return this._excludeHostsForProxy;
}
public get fontSize() {
return this._fontSize;
}
public get fontFamily() {
return this._fontFamily;
}
public get fontWeight() {
return this._fontWeight;
}
public get environmentVariables() {
return this._environmentVariables;
}
public get mimeAndFileExtensionMapping() {
return this._mimeAndFileExtensionMapping;
}
public get previewResponseInUntitledDocument() {
return this._previewResponseInUntitledDocument;
}
public get hostCertificates() {
return this._hostCertificates;
}
public get suppressResponseBodyContentTypeValidationWarning() {
return this._suppressResponseBodyContentTypeValidationWarning;
}
public get previewOption() {
return this._previewOption;
}
public get disableHighlightResonseBodyForLargeResponse() {
return this._disableHighlightResonseBodyForLargeResponse;
}
public get disableAddingHrefLinkForLargeResponse() {
return this._disableAddingHrefLinkForLargeResponse;
}
public get largeResponseBodySizeLimitInMB() {
return this._largeResponseBodySizeLimitInMB;
}
public get previewColumn() {
return this._previewColumn;
}
public get previewResponsePanelTakeFocus() {
return this._previewResponsePanelTakeFocus;
}
public get formParamEncodingStrategy() {
return this._formParamEncodingStrategy;
}
public get addRequestBodyLineIndentationAroundBrackets() {
return this._addRequestBodyLineIndentationAroundBrackets;
}
public get decodeEscapedUnicodeCharacters() {
return this._decodeEscapedUnicodeCharacters;
}
public get logLevel() {
return this._logLevel;
}
public get enableSendRequestCodeLens() {
return this._enableSendRequestCodeLens;
}
public get enableCustomVariableReferencesCodeLens() {
return this._enableCustomVariableReferencesCodeLens;
}
public get useContentDispositionFilename() {
return this._useContentDispositionFilename;
}
private readonly brackets: CharacterPair[];
private static _instance: SystemSettings;
public static get Instance(): SystemSettings {
if (!this._instance) {
this._instance = new SystemSettings();
}
return this._instance;
}
private readonly configurationUpdateEventEmitter = new EventEmitter<void>();
public get onDidChangeConfiguration(): Event<void> {
return this.configurationUpdateEventEmitter.event;
}
private constructor() {
this.brackets = configuration.brackets as CharacterPair[];
workspace.onDidChangeConfiguration(() => {
this.initializeSettings();
this.configurationUpdateEventEmitter.fire();
});
window.onDidChangeActiveTextEditor(e => {
if (e) {
this.initializeSettings();
this.configurationUpdateEventEmitter.fire();
}
});
this.initializeSettings();
}
private initializeSettings() {
const document = getCurrentTextDocument();
const restClientSettings = workspace.getConfiguration("rest-client", document?.uri);
this._followRedirect = restClientSettings.get<boolean>("followredirect", true);
this._defaultHeaders = restClientSettings.get<RequestHeaders>("defaultHeaders",
{
"User-Agent": "vscode-restclient"
});
this._showResponseInDifferentTab = restClientSettings.get<boolean>("showResponseInDifferentTab", false);
this._requestNameAsResponseTabTitle = restClientSettings.get<boolean>("requestNameAsResponseTabTitle", false);
this._rememberCookiesForSubsequentRequests = restClientSettings.get<boolean>("rememberCookiesForSubsequentRequests", true);
this._timeoutInMilliseconds = restClientSettings.get<number>("timeoutinmilliseconds", 0);
if (this._timeoutInMilliseconds < 0) {
this._timeoutInMilliseconds = 0;
}
this._excludeHostsForProxy = restClientSettings.get<string[]>("excludeHostsForProxy", []);
this._fontSize = restClientSettings.get<number>("fontSize");
this._fontFamily = restClientSettings.get<string>("fontFamily");
this._fontWeight = restClientSettings.get<string>("fontWeight");
this._environmentVariables = restClientSettings.get<{ [key: string]: { [key: string]: string } }>("environmentVariables", {});
this._mimeAndFileExtensionMapping = restClientSettings.get<{ [key: string]: string }>("mimeAndFileExtensionMapping", {});
this._previewResponseInUntitledDocument = restClientSettings.get<boolean>("previewResponseInUntitledDocument", false);
this._previewColumn = this.parseColumn(restClientSettings.get<string>("previewColumn", "two"));
this._previewResponsePanelTakeFocus = restClientSettings.get<boolean>("previewResponsePanelTakeFocus", true);
this._hostCertificates = restClientSettings.get<HostCertificates>("certificates", {});
this._disableHighlightResonseBodyForLargeResponse = restClientSettings.get<boolean>("disableHighlightResonseBodyForLargeResponse", true);
this._disableAddingHrefLinkForLargeResponse = restClientSettings.get<boolean>("disableAddingHrefLinkForLargeResponse", true);
this._largeResponseBodySizeLimitInMB = restClientSettings.get<number>("largeResponseBodySizeLimitInMB", 5);
this._previewOption = ParsePreviewOptionStr(restClientSettings.get<string>("previewOption", "full"));
this._formParamEncodingStrategy = ParseFormParamEncodingStr(restClientSettings.get<string>("formParamEncodingStrategy", "automatic"));
this._enableTelemetry = restClientSettings.get<boolean>('enableTelemetry', true);
this._suppressResponseBodyContentTypeValidationWarning = restClientSettings.get('suppressResponseBodyContentTypeValidationWarning', false);
this._addRequestBodyLineIndentationAroundBrackets = restClientSettings.get<boolean>('addRequestBodyLineIndentationAroundBrackets', true);
this._decodeEscapedUnicodeCharacters = restClientSettings.get<boolean>('decodeEscapedUnicodeCharacters', false);
this._logLevel = ParseLogLevelStr(restClientSettings.get<string>('logLevel', 'error'));
this._enableSendRequestCodeLens = restClientSettings.get<boolean>('enableSendRequestCodeLens', true);
this._enableCustomVariableReferencesCodeLens = restClientSettings.get<boolean>('enableCustomVariableReferencesCodeLens', true);
this._useContentDispositionFilename = restClientSettings.get<boolean>('useContentDispositionFilename', true);
languages.setLanguageConfiguration('http', { brackets: this._addRequestBodyLineIndentationAroundBrackets ? this.brackets : [] });
const httpSettings = workspace.getConfiguration("http");
this._proxy = httpSettings.get<string>('proxy');
this._proxyStrictSSL = httpSettings.get<boolean>('proxyStrictSSL', false);
}
private parseColumn(value: string): ViewColumn {
value = value.toLowerCase();
switch (value) {
case 'current':
return ViewColumn.Active;
case 'beside':
default:
return ViewColumn.Beside;
}
}
}
export class RequestSettings implements Partial<IRestClientSettings> {
private _followRedirect?: boolean = undefined;
public get followRedirect() {
return this._followRedirect;
}
public constructor(metadatas: Map<RequestMetadata, string | undefined>) {
if (metadatas.has(RequestMetadata.NoRedirect)) {
this._followRedirect = false;
}
}
}
export class RestClientSettings implements IRestClientSettings {
public get followRedirect() {
return this.requestSettings.followRedirect ?? this.systemSettings.followRedirect;
}
public get defaultHeaders() {
return this.systemSettings.defaultHeaders;
}
public get timeoutInMilliseconds() {
return this.systemSettings.timeoutInMilliseconds;
}
public get showResponseInDifferentTab() {
return this.systemSettings.showResponseInDifferentTab;
}
public get requestNameAsResponseTabTitle() {
return this.systemSettings.requestNameAsResponseTabTitle;
}
public get proxy() {
return this.systemSettings.proxy;
}
public get proxyStrictSSL() {
return this.systemSettings.proxyStrictSSL;
}
public get rememberCookiesForSubsequentRequests() {
return this.systemSettings.rememberCookiesForSubsequentRequests;
}
public get enableTelemetry() {
return this.systemSettings.enableTelemetry;
}
public get excludeHostsForProxy() {
return this.systemSettings.excludeHostsForProxy;
}
public get fontSize() {
return this.systemSettings.fontSize;
}
public get fontFamily() {
return this.systemSettings.fontFamily;
}
public get fontWeight() {
return this.systemSettings.fontWeight;
}
public get environmentVariables() {
return this.systemSettings.environmentVariables;
}
public get mimeAndFileExtensionMapping() {
return this.systemSettings.mimeAndFileExtensionMapping;
}
public get previewResponseInUntitledDocument() {
return this.systemSettings.previewResponseInUntitledDocument;
}
public get hostCertificates() {
return this.systemSettings.hostCertificates;
}
public get suppressResponseBodyContentTypeValidationWarning() {
return this.systemSettings.suppressResponseBodyContentTypeValidationWarning;
}
public get previewOption() {
return this.systemSettings.previewOption;
}
public get disableHighlightResonseBodyForLargeResponse() {
return this.systemSettings.disableHighlightResonseBodyForLargeResponse;
}
public get disableAddingHrefLinkForLargeResponse() {
return this.systemSettings.disableAddingHrefLinkForLargeResponse;
}
public get largeResponseBodySizeLimitInMB() {
return this.systemSettings.largeResponseBodySizeLimitInMB;
}
public get previewColumn() {
return this.systemSettings.previewColumn;
}
public get previewResponsePanelTakeFocus() {
return this.systemSettings.previewResponsePanelTakeFocus;
}
public get formParamEncodingStrategy() {
return this.systemSettings.formParamEncodingStrategy;
}
public get addRequestBodyLineIndentationAroundBrackets() {
return this.systemSettings.addRequestBodyLineIndentationAroundBrackets;
}
public get decodeEscapedUnicodeCharacters() {
return this.systemSettings.decodeEscapedUnicodeCharacters;
}
public get logLevel() {
return this.systemSettings.logLevel;
}
public get enableSendRequestCodeLens() {
return this.systemSettings.enableSendRequestCodeLens;
}
public get enableCustomVariableReferencesCodeLens() {
return this.systemSettings.enableCustomVariableReferencesCodeLens;
}
public get useContentDispositionFilename() {
return this.systemSettings.useContentDispositionFilename;
}
private readonly systemSettings = SystemSettings.Instance;
public constructor(private readonly requestSettings: RequestSettings) {
}
}