Skip to content

Commit

Permalink
correct problem with nested Request handling
Browse files Browse the repository at this point in the history
  • Loading branch information
rentallect committed Sep 18, 2023
1 parent f1fd5c1 commit 101c024
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/http/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ function HttpBody(body, init = {
body = Buffer.from(body.buffer, body.byteOffset, body.byteLength);
} else if (body instanceof Stream) {
// body is stream
} else if (body instanceof ReadableStream) {
async function toBuffer(stream) {
const list = []
const reader = stream.getReader()
while (true) {
const { value, done } = await reader.read()
if (value)
list.push(value)
if (done)
break
}
return Buffer.concat(list)
}
body = toBuffer(body);
// } else if (typeof body.getBoundary === 'function') {
// // detect form data input from form-data module
// // return `multipart/form-data;boundary=${body.getBoundary()}`;
Expand Down
23 changes: 21 additions & 2 deletions src/http/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,15 @@ limitations under the License.
parsedURL = new URL(input.url);
}

let method = init.method || input.method || 'GET';
let method = init.method || input.method;
if (isUndefined(method)) {
if (init.urlObj instanceof Request) {
method = init.urlObj.method;
}
else {
method = 'GET';
}
}

method = method.toUpperCase();

Expand All @@ -106,13 +114,24 @@ limitations under the License.
isRequest(input) && input.body !== null ?
clone(input) :
null;
if (inputBody === null) {
if (init.urlObj instanceof Request) {
inputBody = init.urlObj.body;
}
}

HttpBody.call(this, inputBody, {
timeout: init.timeout || input.timeout || 0,
size: init.size || input.size || 0
});

const headers = new HttpHeaders(init.headers || input.headers || {});

if (init.urlObj instanceof Request) {
for (var pair of init.urlObj.headers.entries()) {
headers.append(pair[0], pair[1]);
}
}

if (this.body instanceof ZitiFormData) {
inputBody = this.body;
Expand Down Expand Up @@ -199,7 +218,7 @@ ZitiHttpRequest.prototype.getServiceConnectAppData = function() {
const parsedURL = this[INTERNALS].parsedURL;
const headers = this[INTERNALS].headers;

// Transform all occurances of the HTTP Agent hostname back to the target service name
// Transform all occurrences of the HTTP Agent hostname back to the target service name
var replace = this.getZitiContext().bootstrapperTargetService;
var re = new RegExp(replace,"i");
parsedURL.href = parsedURL.href.replace(re, replace);
Expand Down

0 comments on commit 101c024

Please sign in to comment.