从相对 URL(给定基本 URL)确定完整 URL 的最快方法是什么
我目前正在使用模块 URI::URL
从相对 URL 生成完整 URL; 但是,它的运行速度没有我希望的那么快。 有谁知道另一种可能更快的方法?
I'm currently using the module URI::URL
to generate a full URL from a relative URL; however, it isn't running as fast as I'd like it to be. Does anyone know another way to do this that may be faster?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
也许我搞错了,但行不通
? IIRC Perl 文本处理速度非常快。
@lennysan 啊,当然可以。 抱歉我无能为力,我的 Perl 已经很生疏了。
Perhaps I got the wrong end of the stick but wouldn't,
work? IIRC Perl text processing is pretty quick.
@lennysan Ah sure yes of course. Sorry I can't help, my Perl is pretty rusty.
可能取决于你如何获得这两个字符串。 也许安全、防火的方法就是 URI::URL 或类似库中的方法,其中将考虑所有替代方案,包括恶意方案。 也许会慢一些,但在某些环境下,子弹飞到你自己脚上的速度会更快。
但是,如果您期望有一些简单且不棘手的内容,可以查看它是否以 /、../ 链或任何其他字符开头。 第一个将放置服务器名称 + url,第二个从基本 uri 开始的切路径,直到进入其他 2 个替代方案之一,或者只是将其添加到基本 url。
Could depend a bit how you obtain those 2 strings. Probably the secure, fireproof way to do that is what is in URI::URL or similar libraries, where all alternatives, including malicious ones, would be considered. Maybe slower, but in some environments faster will be the speed of a bullet going to your own foot.
But if you expect there something plain and not tricky could see if it starts with /, chains of ../, or any other char. The 1st would put the server name + the url, the 2nd chop paths from the base uri till getting in one of the other 2 alternatives, or just add it to the base url.
布伦丹,我应该澄清一下,我不能保证相对路径会是什么样子。 它可能非常棘手(例如前面有斜杠、没有斜杠、有“../”等)。
彼得,这就是我现在正在使用的。 或者比使用 URI::URL->new($path)->abs 更快?
Brendan, I should have clarified that I can't guarantee what the relative path is going to look like. It could be pretty tricky (e.g. has a slash at the front, doesn't have a slash, has "../", etc).
Peter, that's what I'm using now. Or is that faster then using the URI::URL->new($path)->abs?
下面的代码应该可以工作。
您还应该查看search.cpan.org 上的 URI 页面 。
The following code should work.
You should also take a look at the URI page on search.cpan.org.
刚刚发生在这篇文章中解决 Redhat/Centos/Fedora Perl 实现中对
URI
产生深远影响的缺陷。如果您正在运行这些 Linux 版本之一,您可能需要从原始源代码(而不是 RPM 源代码)重新编译 Perl。
Just happened across this article which point out shortcomings in Redhat/Centos/Fedora implementations of Perl which affect
URI
profoundly.If you are running one of these Linux flavours, you might want to recompile Perl from original source (not RPM source).