mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-17 02:51:36 -05:00
Fix http request format (#22618)
* fix http request format * encode to utf 8 and add body for put requests * encode proxy request body * change ?.data to ?.body * add note for textencoder * change content-type to application/json
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
import { INetworkModule, NetworkRequestOptions, NetworkResponse } from '@azure/msal-common';
|
||||
import * as http from 'http';
|
||||
import * as https from 'https';
|
||||
import { TextEncoder } from 'util';
|
||||
import { NetworkUtils } from './networkUtils';
|
||||
|
||||
/**
|
||||
@@ -151,9 +152,10 @@ const networkRequestViaProxy = <T>(
|
||||
// compose a request string for the socket
|
||||
let postRequestStringContent: string = '';
|
||||
if (httpMethod === HttpMethod.POST || httpMethod === HttpMethod.PUT) {
|
||||
const body = options?.body || '';
|
||||
// Note: Text Encoder is necessary here because otherwise it was not able to handle Chinese characters in table names.
|
||||
const body = (new TextEncoder()).encode(JSON.stringify(options?.body || ''));
|
||||
postRequestStringContent =
|
||||
'Content-Type: application/x-www-form-urlencoded\r\n' +
|
||||
'Content-Type: application/json\r\n' +
|
||||
`Content-Length: ${body.length}\r\n` +
|
||||
`\r\n${body}`;
|
||||
}
|
||||
@@ -284,7 +286,8 @@ const networkRequestViaHttps = <T>(
|
||||
): Promise<NetworkResponse<T>> => {
|
||||
const isPostRequest = httpMethod === HttpMethod.POST;
|
||||
const isPutRequest = httpMethod === HttpMethod.PUT;
|
||||
const body: string = options?.body || '';
|
||||
// Note: Text Encoder is necessary here because otherwise it was not able to handle Chinese characters in table names.
|
||||
const body = (new TextEncoder()).encode(JSON.stringify(options?.body || ''));
|
||||
const url = new URL(urlString);
|
||||
const optionHeaders = options?.headers || {} as Record<string, string>;
|
||||
let customOptions: https.RequestOptions = {
|
||||
@@ -319,7 +322,7 @@ const networkRequestViaHttps = <T>(
|
||||
});
|
||||
}
|
||||
|
||||
if (isPostRequest) {
|
||||
if (isPostRequest || isPutRequest) {
|
||||
request.write(body);
|
||||
}
|
||||
|
||||
|
||||
@@ -501,7 +501,7 @@ export async function createResourceGroup(account: AzureAccount, subscription: a
|
||||
const host = getProviderMetadataForAccount(account).settings.armResource.endpoint;
|
||||
const response = await makeHttpRequest(account, subscription, path, HttpRequestMethod.PUT, requestBody, ignoreErrors, host);
|
||||
return {
|
||||
resourceGroup: response?.response?.data,
|
||||
resourceGroup: response?.response?.body,
|
||||
errors: response.errors ? response.errors : []
|
||||
};
|
||||
}
|
||||
@@ -511,8 +511,8 @@ export async function getStorageAccountAccessKey(account: AzureAccount, subscrip
|
||||
const host = getProviderMetadataForAccount(account).settings.armResource.endpoint;
|
||||
const response = await makeHttpRequest(account, subscription, path, HttpRequestMethod.POST, undefined, ignoreErrors, host);
|
||||
return {
|
||||
keyName1: response?.response?.data?.keys[0].value ?? '',
|
||||
keyName2: response?.response?.data?.keys[0].value ?? '',
|
||||
keyName1: response?.response?.body?.keys[0].value ?? '',
|
||||
keyName2: response?.response?.body?.keys[0].value ?? '',
|
||||
errors: response.errors ? response.errors : []
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user