What is the fastest way to determine the full URL from a relative URL (given the base URL)

I am currently using the URI::URL module to create a full URL from a relative URL; however, it does not work as fast as we would like. Does anyone know another way to do this, which could be faster?

+4
source share
5 answers

The following code should work.

 $uri = URI->new_abs( $str, $base_uri ) 

You should also take a look at the URI page at search.cpan.org .

+3
source

Happened through in this article , which points out flaws in Redhat / Centos / Fedora Perl implementations that have a big impact on URI .

If you use one of these Linux accessories, you may need to recompile Perl from the original source (not the RPM source).

I realized that anyone working with perl code with a perl interpreter for a distribution on Redhat 5.2, Centos 5.2 or Fedora 9 is probably the victim. Yes, even if your code does not use a fancy blessing / overload idol, many CPAN modules do! This google search shows that 1500+ modules use the blessing / overload idiom, and they include some really popular ones such as URIs, JSON ....

... At this point, I decided to recompile perl from the source. The error has disappeared. And the difference was terrifying. Everything turned out seriously quickly. The processors cooled when loadavg was below 0.10, and we processed data from 100x to 1000x faster!

+4
source

Brendan, I had to clarify that I canโ€™t guarantee what the relative path will look like. This can be quite difficult (for example, it has a slash in front, does not have a slash, has "../", etc.).

Peter, this is what I'm using right now. Or is it faster than using URI :: URL-> new ($ path) โ†’ abs?
+1
source

It may depend a bit on how you get these 2 lines. Probably a safe, fireproof way to do this is to find it in a URI :: URL or similar library, where all alternatives, including malware, will be considered. It may be slower, but in some environments the speed of a bullet reaching your own leg will be faster.

But if you expect something simple rather than complex, you can see if it starts with /, chains ../ or any other char. The first will put the server name + url, 2 chop paths from the base uri until one of the two alternatives 2 is received, or just add it to the base url.

+1
source

Maybe I got the wrong end of the stick, but I didnโ€™t want

 $full_url = $base_url . $relative_url 

work? IIRC Perl text processing is pretty fast.

@lennysan Of course, yes, of course. Sorry, I canโ€™t help, my Perl is pretty rusty.

0
source

Source: https://habr.com/ru/post/1276429/


All Articles