-
Notifications
You must be signed in to change notification settings - Fork 26
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
URL's on incoming requests #71
Comments
I'm highly -1 on using |
I usually use, https://www.npmjs.com/package/request-target. Maybe worth looking into? |
https://github.com/nodejs/next-10/blob/master/VALUES_AND_PRIORITIZAION.md might also be worth considering, i.e. "Performance" vs "Web API compatibility". |
could we do something like Additionally, could we look into improving |
This is why I was strongly questioning adding that (nodejs/node#35323) in yesterdays meeting. The perf is a big concern I was not aware of (do we have benchmarks on this, or details on why?), but is also a good reason to push back on the web api compat technical value issue. |
From https://www.npmjs.com/package/request-target
|
I hadn't clicked your link, but yeah this looks good. I will dig into what it is doing, thanks for the link! |
Well I very quickly ended on this line, and I am fairly confident we will be able to find a better (and even better perf) way than a big regex. But this leads me to my next question: do we really want to deviate from the existing URL apis? Seems like this would add "yet another url" to node core, right? Maybe we could get fast parsing but also expose an api which looks like a |
Is the slow performance of If its the latter, then this would be a good excuse to re-evaluate the implementation to squeeze out better performance. |
Overall, I think providing a way to retrieve Using standard JS One of the big foot-guns today is parsing url query string params. Consider this code: const { parse } = require('url');
const handler = (req, res) => {
let { pathname = '/', query = {} } = parse(req.url || '', true);
const { user = '' } = query;
console.log(user.toLowerCase());
} This works fine with Consider this similar code using URL: const handler = (req, res) => {
const url = new URL(req.url, 'https://example.com');
const user = url.searchParams.get('user') || '';
console.log(user.toLowerCase());
} This bug doesn't happen with URL because it separates My workaround for the time being looks like this: export function getURL(req) {
const proto = req.headers['x-forwarded-proto'] || 'https';
const host = req.headers['x-forwarded-host'] || req.headers.host || 'example.com';
return new URL(req.url || '/', `${proto}://${host}`);
} |
It makes sense to me to offer both (obviously under different names) - ie, |
I think before we make any decisions on this, we need to know if we can help fix the perf issues of
@styfle There are security concerns here, but if we "do it right" I think it is a reasonable approach (if you know those headers can only be set by trusted proxies, you should be fine). The added support for the meta headers would also change this a bit, but not in a bad way. Also, we would default them to the values computed from |
Why both when there's |
Modifying |
I don't think this is an issue if we are discussing a whole new API |
Maybe I misunderstood the intent of this discussion 🤔 I thought If you modify the |
Possibly a tangent, but if I were to pick the naming, I would use And if I were modifying the Node.js API, I would deprecate |
This discussion is related to this: #55 Because the entire api will be new, breaking is fine.
While I see the goal of this naming, I am strongly against bikeshedding names (at least at this point). I also do not think this would be a meaningful change, nor one which would make it easier/better for any of our constituencies. Once we nail down the particulars of what we need to offer on this api, we can discuss again if name changes will be something to pursue, but lets keep on focus for now. |
To recap our discussion on the meeting today: What would folks think of providing an api at server creation time to pass your url implementation. By default we would create a |
I'm still generically -1 to the idea of using
in a hot path by default. A similar discussion can be made for the None of this was defined with throughput in mind. If we want Node.js to shine, it needs to be faster, not slower. |
@mcollina "better" is better than "faster" too. |
Agree with @mcollina. Anything that affects performance should be opt-in. In this particular case, if I don't need to parse the URL in most of my requests, why would I pay the price on all of them? |
The plan which @ronag and I discussed in this gist involves a multi-layer api. As a compromise, if we kept the "core" api with the string |
Can you elaborate on:
and
|
I think we should probably agree on which APIs have which intended constituencies. @ronag outlined a bit of what the goals of the different
One of the proposals above was to utilize a specialty parser like |
And what is wrong with using: const url = new URL(req.url); Seems simple enough if a user wants to parse the URL and can also be provided by the frameworks if they must...
agree with you and I believe this gives an opportunity to let users (or frameworks) chose how they want to parse a URL. As you suggested, we can provide a function to http.createServer({
allowHTTP1: true,
parseUrl(stringUrl) {
return new URL(stringUrl);
}
}) |
Agreed, that will likely lead to more confusion.
@wesleytodd In addition to pathname, I think query string is quite common too.
@mcollina I'm not sure that solves the problem of parsing |
thanks for your message @styfle ! But this group isn't really active anymore (last two years I would say) |
I see. I've been bouncing around different issues and all seem to be dead ends. |
I think |
Either option sounds great! We could use |
|
would you like to send a PR for this? |
How is |
Looks like someone already did: watson/original-url#11 |
issue related: nodejs/node#51311 |
Initial context: nodejs/node#12682
I think the new api's should use
URL
as the basis forreq.url
(or whatever equivalent we expose). As you can see from the thread above, there is some question about how today these are relative urls and the new spec does not support that. My thought, and what I think we need to discuss, is that the "base" should be derived from the incoming request headers and fall back to the server address.If we come to an agreement on this I am happy to write up a more detailed description. Agenda added so we can discuss in the next meeting as well.
The text was updated successfully, but these errors were encountered: