-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Virtual network part 2 #1126
Virtual network part 2 #1126
Conversation
…n of virtual network now
@ef4 @lukemelia an update:
I feel that this change might not be aligned with the vision for the virtual network so I'd like to discuss this. Perhaps the realm server should not know about resolved urls and the mentioned redirection logic should be moved to the virtual network as handlers?
|
Follow up comments to issue described in (2), did some discussing with @lukemelia–a couple of ideas to make the
|
This fixes an error when closeHandlers.get(request)!.on('close', fn) errors out because the copied request can't be found in the closeHandlers weak map
…e a real url (not virtual)
This PR leverages the virtual network in such a way that:
This refactor is an intermediate step towards having isolated loaders that share a virtual network. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
Extract PackageShimHandler as its own simple class instead of using Loader
|
||
let body = null; | ||
if (originalRequest.body) { | ||
body = await getContentOfReadableStream(originalRequest.clone().body); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've been trying to see if I can get rid of body stream reading to create a new request with a changed url but to no avail...
Object.defineProperty(request, 'url', { value: mappedUrl })
will not work because the underlying url value really is immutable. Here is a demonstration - the request will still try to reach the original url even when trying to override it withdefineProperty
:
- I saw some hints online that tee could be used to copy the body, like so:
let copiedBody = null;
if (originalRequest.body) {
copiedBody = originalRequest.body.tee()[0];
}
return new Request(url, {
method: originalRequest.method,
headers: originalRequest.headers,
body: copiedBody,
referrer: originalRequest.referrer,
referrerPolicy: originalRequest.referrerPolicy,
mode: originalRequest.mode,
credentials: originalRequest.credentials,
cache: originalRequest.cache,
redirect: originalRequest.redirect,
integrity: originalRequest.integrity,
});
But again, the error persists:
clone()
-ing the request and taking its body won't work either (failing with the same error):
return new Request(url, {
method: originalRequest.method,
headers: originalRequest.headers,
body: originalRequest.clone().body,
referrer: originalRequest.referrer,
referrerPolicy: originalRequest.referrerPolicy,
mode: originalRequest.mode,
credentials: originalRequest.credentials,
cache: originalRequest.cache,
redirect: originalRequest.redirect,
integrity: originalRequest.integrity,
});
It is interesting because Safari gives a different error message:
- But what if we try adding the
duplex
property?
let requestInit: RequestInit = originalRequest.clone();
if (originalRequest.body) {
requestInit.duplex = 'half';
}
return new Request(url, requestInit);
The request will fail with net::ERR_H2_OR_QUIC_REQUIRED
which is indicative of missing http2 support on the server:
Moreover, TypeScript doesn't recognize duplex
property on the Request
- looks like this is more of an experimental thing for now...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thought would be to Proxy the request:
let proxiedRequest = new Proxy(originalRequest, {
get(target, property, received) {
if (property === 'url') {
return mappedURL;
}
return Reflect.get(target, property, received);
}
})
No description provided.