Skip to content

Commit 85c8921

Browse files
authored
fix: fix issues with http requests (#480)
* Fix port in http request * Add post data to http request if present * Convert base64 to text if necessary
1 parent 96ff42b commit 85c8921

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/behavior-router.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,12 @@ export class BehaviorRouter {
177177
res.setHeader(key as string, value);
178178
}
179179
}
180-
181-
res.end(response.body);
180+
181+
if (response.bodyEncoding === 'base64') {
182+
res.end(Buffer.from(response.body, 'base64').toString('utf-8'));
183+
} else {
184+
res.end(response.body);
185+
}
182186
} catch (err) {
183187
this.handleError(err, res);
184188
return;

src/services/origin.service.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export class Origin {
123123
method: request.method,
124124
protocol: baseUrl.protocol,
125125
hostname: baseUrl.hostname,
126-
port: baseUrl.port || (baseUrl.protocol === 'https:') ? 443 : 80,
126+
port: baseUrl.port || (baseUrl.protocol === 'https:' ? 443 : 80),
127127
path: uri.path,
128128
headers: {
129129
...headers,
@@ -144,7 +144,9 @@ export class Origin {
144144
});
145145
res.on('error', (err: Error) => reject(err));
146146
});
147-
147+
if (request.body && request.body.data) {
148+
req.write(request.body.data);
149+
}
148150
req.end();
149151
});
150152
}

0 commit comments

Comments
 (0)