Skip to content
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

This URI is not valid #80

Closed
antoniogamiz opened this issue Jul 28, 2019 · 3 comments
Closed

This URI is not valid #80

antoniogamiz opened this issue Jul 28, 2019 · 3 comments

Comments

@antoniogamiz
Copy link

antoniogamiz commented Jul 28, 2019

I am trying to make a GET HTTP request to this link => https://docs.perl6.org/language/variables#index-entry-\_(sigilless_variables), but Cro::HTTP::Client throws the following error:

Unable to parse URI '/language/variables#index-entry-\_(sigilless_variables)': unexpected text at end
  in method panic at /home/antonio/.perl6/sources/60785334089CA46B3D28A575820E0BBA6CCD0778 (Cro::Uri) line 174
  in regex relative-ref at /home/antonio/.perl6/sources/60785334089CA46B3D28A575820E0BBA6CCD0778 (Cro::Uri) line 153
  in regex ref at /home/antonio/.perl6/sources/60785334089CA46B3D28A575820E0BBA6CCD0778 (Cro::Uri) line 148
  in method parse-ref at /home/antonio/.perl6/sources/60785334089CA46B3D28A575820E0BBA6CCD0778 (Cro::Uri) line 323
  in method add at /home/antonio/.perl6/sources/60785334089CA46B3D28A575820E0BBA6CCD0778 (Cro::Uri) line 365
  in method request at /home/antonio/.perl6/sources/6A7961F2D42481B23E10B8CD3FA6044159D086C1 (Cro::HTTP::Client) line 332
  in method get at /home/antonio/.perl6/sources/6A7961F2D42481B23E10B8CD3FA6044159D086C1 (Cro::HTTP::Client) line 290
  in sub check-page at test.p6 line 57
  in block <unit> at test.p6 line 81

Since this page exists and is valid, I believe that url is valid. Any ideas about what's happening?

More examples:

@Altai-man
Copy link
Member

The URL is not valid. The issue with this URL is that, as I see, you are trying to do:

get('/language/variables#index-entry-_(sigilless_variables)')

but \ character is illegal in urls and must be encoded as %5C. When I copy the url from firefox address bar, I am getting:

https://docs.perl6.org/language/variables#index-entry-%5C_(sigilless_variables)

In clipboard, it means it is properly encoded, but browser just shows you "pretty" url, just as it does with fancy Unicode symbols etc.

In order to use it, you need to escape those characters. I don't know what is the source of your urls to get, so can't suggest anything here.

The second thing I can note is that every URL you provided has illegal characters in query part(after #) and I don't think curl or cro considers it. So for

https://docs.perl6.org/language/operators#postcircumfix_{_}

in fact, page at https://docs.perl6.org/language/operators will be downloaded. And it will be downloaded even if the anchor does not exist on page, for example:

➜  ~ perl6 -e 'use Cro::HTTP::Client; Cro::HTTP::Client.get(\'https://docs.perl6.org/language/operators#something-that-does-not-exist\', :http<1.1>).result.say'
Cro::HTTP::Response.new(request => Cro::HTTP::Request.new(body-parser-selector => Cro::HTTP::BodyParserSelector::RequestDefault, body-serializer-selector => Cro::HTTP::BodySerializerSelector::RequestDefault, connection => Any, method => "GET", target => "/language/operators", original-target => Str, auth => Any, annotations => {}, http-version => Str, http2-stream-id => Int), status => 200, body-parser-selector => Cro::HTTP::BodyParserSelector::ResponseDefault, body-serializer-selector => Cro::HTTP::BodySerializerSelector::ResponseDefault, http-version => "1.1", http2-stream-id => Int)

I also recommend using :http<1.1> as HTTP/2 support is limited.

@antoniogamiz
Copy link
Author

Agh, I did not realize browser was encoding the url automatically. Thanks for your time and advise! 💯 .

@JJ
Copy link

JJ commented Oct 8, 2020

Still, it's CRO::Uri who's throwing this error. Shouldn't it be Cro::URI the ones that encodes that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants