From b8b88f99dcf07168b58d8a04b46b82b24b65a0fc Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Wed, 8 Aug 2018 22:12:14 -0300 Subject: Encode just the params for the request --- lib/Matrix/Client/Requester.pm6 | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/Matrix/Client/Requester.pm6 b/lib/Matrix/Client/Requester.pm6 index 68c0323..22c91c6 100644 --- a/lib/Matrix/Client/Requester.pm6 +++ b/lib/Matrix/Client/Requester.pm6 @@ -27,12 +27,12 @@ method !access-token-arg { } method get(Str $path, :$media = False, *%data) { - my $q = "$path?{self!access-token-arg}"; + my $query = "?{self!access-token-arg}"; for %data.kv -> $k,$v { - $q ~= "&$k=$v" if $v.so; + $query ~= "&$k=$v" if $v.so; } - my $uri = uri_encode($.base-url(:$media) ~ $q); - + my $encoded-path = $path.subst('#', '%23'); + my $uri = $.base-url(:$media) ~ $encoded-path ~ uri_encode($query); return self!handle-error($!ua.get($uri)); } @@ -45,7 +45,8 @@ method base-url(Bool :$media? = False --> Str) { } multi method post(Str $path, Str $json, :$media = False) { - my $url = $.base-url(:$media) ~ $path ~ "?{self!access-token-arg}"; + my $encoded-path = $path.subst('#', '%23'); + my $url = $.base-url(:$media) ~ $encoded-path ~ "?{self!access-token-arg}"; my $req = HTTP::Request.new(POST => $url, Content-Type => 'application/json'); $req.add-content($json); @@ -58,12 +59,19 @@ multi method post(Str $path, :$media = False, *%params) { } method post-bin(Str $path, Buf $buf, :$content-type) { - my $req = POST($.base-url(:media) ~ $path ~ "?{self!access-token-arg}", content => $buf, Content-Type => $content-type); + my $encoded-path = $path.subst('#', '%23'); + my $req = POST($.base-url(:media) + ~ $encoded-path + ~ "?{self!access-token-arg}", + content => $buf, + Content-Type => $content-type + ); return self!handle-error($!ua.request($req)); } multi method put(Str $path, Str $json) { - my $req = HTTP::Request.new(PUT => $.base-url() ~ $path ~ "?{self!access-token-arg}", + my $encoded-path = $path.subst('#', '%23'); + my $req = HTTP::Request.new(PUT => $.base-url() ~ $encoded-path ~ "?{self!access-token-arg}", Content-Type => 'application/json'); $req.add-content($json); return self!handle-error($!ua.request($req)) -- cgit v1.2.3-54-g00ecf