Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add setting to display Request Name as Tab Title #400

Merged
merged 5 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ exchange | Preview the whole HTTP exchange(request and response)
* `rest-client.defaultHeaders`: If particular headers are omitted in request header, these will be added as headers for each request. (Default is `{ "User-Agent": "vscode-restclient", "Accept-Encoding": "gzip" }`)
* `rest-client.timeoutinmilliseconds`: Timeout in milliseconds. 0 for infinity. (Default is __0__)
* `rest-client.showResponseInDifferentTab`: Show response in different tab. (Default is __false__)
* `rest-client.requestNameAsResponseTabTitle`: Show request name as the response tab title. Only valid when using html view, if no request name is specified defaults to "Response". (Default is __false__)
* `rest-client.rememberCookiesForSubsequentRequests`: Save cookies from `Set-Cookie` header in response and use for subsequent requests. (Default is __true__)
* `rest-client.enableTelemetry`: Send out anonymous usage data. (Default is __true__)
* `rest-client.excludeHostsForProxy`: Excluded hosts when using proxy settings. (Default is __[]__)
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@
"scope": "resource",
"description": "Show response in different tab"
},
"rest-client.requestNameAsResponseTabTitle": {
"type": "boolean",
"default": false,
"scope": "resource",
"description": "Show request name as the response tab title"
},
"rest-client.rememberCookiesForSubsequentRequests": {
"type": "boolean",
"default": true,
Expand Down
3 changes: 3 additions & 0 deletions src/models/configurationSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export interface IRestClientSettings {
defaultHeaders: Headers;
timeoutInMilliseconds: number;
showResponseInDifferentTab: boolean;
requestNameAsResponseTabTitle: boolean;
proxy: string;
proxyStrictSSL: boolean;
rememberCookiesForSubsequentRequests: boolean;
Expand Down Expand Up @@ -44,6 +45,7 @@ export class RestClientSettings implements IRestClientSettings {
public defaultHeaders: Headers;
public timeoutInMilliseconds: number;
public showResponseInDifferentTab: boolean;
public requestNameAsResponseTabTitle: boolean;
public proxy: string;
public proxyStrictSSL: boolean;
public rememberCookiesForSubsequentRequests: boolean;
Expand Down Expand Up @@ -114,6 +116,7 @@ export class RestClientSettings implements IRestClientSettings {
"Accept-Encoding": "gzip"
});
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) {
Expand Down
4 changes: 2 additions & 2 deletions src/models/httpRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { Headers } from './base';
import { RequestVariableCacheKey } from './requestVariableCacheKey';

export class HttpRequest {
public requestVariableCacheKey?: RequestVariableCacheKey;
public constructor(
public method: string,
public url: string,
public headers: Headers,
public body: string | Stream,
public rawBody: string) {
public rawBody: string,
public requestVariableCacheKey?: RequestVariableCacheKey) {
}

public getHeader(name: string) {
Expand Down
3 changes: 2 additions & 1 deletion src/utils/httpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ export class HttpClient {
options.url,
HttpClient.capitalizeHeaderName(response.toJSON().request.headers),
Buffer.isBuffer(requestBody) ? that.convertBufferToStream(requestBody) : requestBody,
httpRequest.rawBody
httpRequest.rawBody,
httpRequest.requestVariableCacheKey
)));
})
.on('data', function (data) {
Expand Down
8 changes: 4 additions & 4 deletions src/views/httpResponseWebview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ export class HttpResponseWebview extends BaseWebview {
}

public async render(response: HttpResponse, column: ViewColumn) {
const tabTitle = this.settings.requestNameAsResponseTabTitle && response.request.requestVariableCacheKey && response.request.requestVariableCacheKey.key || 'Response';
let panel: WebviewPanel;
if (this.settings.showResponseInDifferentTab || this.panels.length === 0) {
panel = window.createWebviewPanel(
this.viewType,
`Response(${response.elapsedMillionSeconds}ms)`,
`${tabTitle}(${response.elapsedMillionSeconds}ms)`,
{ viewColumn: column, preserveFocus: !this.settings.previewResponsePanelTakeFocus },
{
enableFindWidget: true,
Expand Down Expand Up @@ -88,7 +89,7 @@ export class HttpResponseWebview extends BaseWebview {
this.panels.push(panel);
} else {
panel = this.panels[this.panels.length - 1];
panel.title = `Response(${response.elapsedMillionSeconds}ms)`;
panel.title = `${tabTitle}(${response.elapsedMillionSeconds}ms)`;
}

panel.webview.html = this.getHtmlForWebview(response);
Expand Down Expand Up @@ -348,5 +349,4 @@ ${HttpResponseWebview.formatHeaders(response.headers)}`;
class FoldingRange {
public constructor(public start: number, public end: number) {
}
}

}