@@ -10,16 +10,16 @@ import { FormData } from "formdata-node";
1010import { Readable } from "stream" ;
1111import * as path from "path" ;
1212
13- export function constructGotRequest ( allData : RequestSpec ) : GotRequest {
13+ export function constructGotRequest ( allData : RequestSpec , workingDir ?: string ) : GotRequest {
1414 const completeUrl : string = getURL (
1515 allData . httpRequest . baseUrl ,
1616 allData . httpRequest . url ,
17- getParamsForUrl ( allData . httpRequest . params , allData . options . rawParams ) ,
17+ getParamsForUrl ( allData . httpRequest . params , allData . options . rawParams )
1818 ) ;
1919
2020 const options : OptionsOfTextResponseBody = {
2121 method : allData . httpRequest . method . toLowerCase ( ) as Method ,
22- body : getBody ( allData ) ,
22+ body : getBody ( allData , workingDir ) ,
2323 headers : allData . httpRequest . headers ,
2424 followRedirect : allData . options . follow ,
2525 https : { rejectUnauthorized : allData . options . verifySSL } ,
@@ -29,8 +29,13 @@ export function constructGotRequest(allData: RequestSpec): GotRequest {
2929 return got ( completeUrl , options ) ;
3030}
3131
32- function getFileFromPath ( filePath : string ) {
33- filePath = path . resolve ( filePath . slice ( 7 ) ) ; // removes file:// prefix
32+ function getFileFromPath ( filePath : string , workingDir ?: string ) {
33+ if ( workingDir ) {
34+ filePath = path . resolve ( workingDir , filePath . slice ( 7 ) ) ; // removes <file://> prefix
35+ } else {
36+ filePath = path . resolve ( filePath . slice ( 7 ) ) ; // takes current working directory
37+ }
38+
3439 const fileName = path . basename ( filePath ) ;
3540 return fileFromPathSync ( filePath , fileName ) ;
3641}
@@ -50,14 +55,14 @@ function constructFormUrlEncoded(request: RequestSpec) {
5055 return result . toString ( ) ;
5156}
5257
53- function constructFormData ( request : RequestSpec ) {
58+ function constructFormData ( request : RequestSpec , workingDir ?: string ) {
5459 const formValues = request . httpRequest . formValues ;
5560 if ( ! formValues ) return ;
5661 const multipart = new FormData ( ) ;
5762
5863 for ( const fv of formValues ) {
5964 if ( isFilePath ( fv . value ) ) {
60- multipart . append ( fv . name , getFileFromPath ( fv . value ) ) ;
65+ multipart . append ( fv . name , getFileFromPath ( fv . value , workingDir ) ) ;
6166 } else {
6267 multipart . append ( fv . name , fv . value ) ;
6368 }
@@ -68,12 +73,12 @@ function constructFormData(request: RequestSpec) {
6873 return Readable . from ( fde ) ;
6974}
7075
71- export function getBody ( request : RequestSpec ) {
76+ export function getBody ( request : RequestSpec , workingDir ?: string ) {
7277 const body = request . httpRequest . body ;
7378 const formValues = request . httpRequest . formValues ;
7479
7580 if ( request . httpRequest . headers [ "content-type" ] == "multipart/form-data" || hasFile ( formValues ) ) {
76- return constructFormData ( request ) ;
81+ return constructFormData ( request , workingDir ) ;
7782 }
7883
7984 if ( formValues ) {
0 commit comments