Skip to content
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
19 changes: 14 additions & 5 deletions ts/src/management/tunnelManagementHttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,13 @@ export class TunnelManagementHttpClient implements TunnelManagementClient {
}
}

options.additionalHeaders = options.additionalHeaders || {};
options.additionalHeaders['If-Not-Match'] = "*";
options = {
...options,
additionalHeaders: {
...options.additionalHeaders,
'If-None-Match': '*',
},
};

if (idGenerated) {
tunnel.tunnelId = IdGeneration.generateTunnelId();
Expand Down Expand Up @@ -578,9 +583,13 @@ export class TunnelManagementHttpClient implements TunnelManagementClient {
this.raiseReportProgress(TunnelProgress.StartingCreateTunnelPort);
tunnelPort = this.convertTunnelPortForRequest(tunnel, tunnelPort);
const path = `${portsApiSubPath}/${tunnelPort.portNumber}`;
options = options || {};
options.additionalHeaders = options.additionalHeaders || {};
options.additionalHeaders['If-Not-Match'] = "*";
options = {
...options,
additionalHeaders: {
...options?.additionalHeaders,
'If-None-Match': '*',
},
};
const result = (await this.sendTunnelRequest<TunnelPort>(
'PUT',
tunnel,
Expand Down
63 changes: 62 additions & 1 deletion ts/test/tunnels-test/tunnelManagementTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import axios, { Axios, AxiosHeaders, AxiosError, AxiosPromise, AxiosRequestConfi
import * as https from 'https';
import { suite, test, slow, timeout } from '@testdeck/mocha';
import { ManagementApiVersions, TunnelManagementHttpClient } from '@microsoft/dev-tunnels-management';
import { Tunnel, TunnelProgress, TunnelReportProgressEventArgs, ClusterRecommendationResponse, ClusterAvailability } from '@microsoft/dev-tunnels-contracts';
import { Tunnel, TunnelPort, TunnelProgress, TunnelReportProgressEventArgs, ClusterRecommendationResponse, ClusterAvailability } from '@microsoft/dev-tunnels-contracts';
import { CancellationToken, CancellationTokenSource } from 'vscode-jsonrpc';

@suite
Expand Down Expand Up @@ -282,6 +282,7 @@ export class TunnelManagementTests {
callCount++;

const sentTunnel = config.data as Tunnel;
assert.strictEqual(config.headers?.['If-None-Match'], '*');
if (callCount === 1) {
firstTunnelId = sentTunnel?.tunnelId;
throw conflictError;
Expand Down Expand Up @@ -315,6 +316,66 @@ export class TunnelManagementTests {
}
}

@test
public async createTunnelSendsIfNoneMatchHeader() {
const requestTunnel = <Tunnel>{
tunnelId: 'tunnelid',
clusterId: 'clusterId',
};
this.nextResponse = <Tunnel>{
tunnelId: 'tunnelid',
clusterId: 'clusterId',
};
const options = {
additionalHeaders: {
'X-Test': 'value',
},
};

await this.managementClient.createTunnel(requestTunnel, options);

assert(this.lastRequest);
const headers = this.lastRequest!.config.headers as { [name: string]: string };
assert.strictEqual(headers['If-None-Match'], '*');
assert.strictEqual(headers['If-Not-Match'], undefined);
assert.strictEqual(headers['X-Test'], 'value');
assert.strictEqual(
Object.prototype.hasOwnProperty.call(options.additionalHeaders, 'If-None-Match'),
false,
);
}

@test
public async createTunnelPortSendsIfNoneMatchHeader() {
const requestTunnel = <Tunnel>{
tunnelId: 'tunnelid',
clusterId: 'clusterId',
};
const requestPort = <TunnelPort>{
portNumber: 9900,
};
this.nextResponse = <TunnelPort>{
portNumber: 9900,
};
const options = {
additionalHeaders: {
'X-Test': 'value',
},
};

await this.managementClient.createTunnelPort(requestTunnel, requestPort, options);

assert(this.lastRequest);
const headers = this.lastRequest!.config.headers as { [name: string]: string };
assert.strictEqual(headers['If-None-Match'], '*');
assert.strictEqual(headers['If-Not-Match'], undefined);
assert.strictEqual(headers['X-Test'], 'value');
assert.strictEqual(
Object.prototype.hasOwnProperty.call(options.additionalHeaders, 'If-None-Match'),
false,
);
}

@test
public async getClusterRecommendationsReturnsResponse() {
const response = <ClusterRecommendationResponse>{
Expand Down
Loading