@@ -2,6 +2,9 @@ import { callback } from "../utils";
22import { parseRequest , ParseRequestResult } from "http-string-parser" ;
33import * as vscode from "vscode" ;
44import { logger } from "../../global/log" ;
5+ import fetch , { type RequestInit , type Response } from "node-fetch" ;
6+ import { Agent as httpsAgent } from "https" ;
7+ import { Agent as HttpAgent } from "http" ;
58
69export const rawHTTPRequest : callback = async ( args ) => {
710 let request : string | undefined = args . request ? args . request : undefined ;
@@ -34,20 +37,26 @@ export const rawHTTPRequest: callback = async (args) => {
3437 headers
3538 ) } , body: ${ body ? body : "none" } `
3639 ) ;
37- let response : Response | undefined = undefined ;
40+ let requestInit : RequestInit = {
41+ method,
42+ headers,
43+ redirect : 'manual' ,
44+ follow : 0 , // Disable automatic following of redirects
45+ } ;
3846 if ( method === "GET" || method === "HEAD" ) {
3947 // For GET and HEAD requests, we should not send a body
40- response = await fetch ( url , {
41- method,
42- headers,
43- } ) ;
48+ requestInit . body = undefined ;
49+ // requestInit.body = body; // Explicitly set body to null for clarity
4450 } else {
45- response = await fetch ( url , {
46- method,
47- headers,
48- body,
51+ requestInit . body = body ;
52+ }
53+ if ( isHTTPS ) {
54+ process . env . NODE_TLS_REJECT_UNAUTHORIZED = '0' ;
55+ requestInit . agent = new httpsAgent ( {
56+ rejectUnauthorized : false , // Disable SSL verification for testing purposes
4957 } ) ;
5058 }
59+ let response : Response = await fetch ( url , requestInit ) ;
5160 let responseText : string = `HTTP/1.1 ${ response . status } ${ response . statusText } \n` ;
5261 for ( const [ key , value ] of response . headers . entries ( ) ) {
5362 responseText += `${ key } : ${ value } \n` ;
0 commit comments