aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatias Linares <matiaslina@gmail.com>2018-08-08 22:12:14 -0300
committerMatias Linares <matiaslina@gmail.com>2018-08-08 22:12:14 -0300
commitb8b88f99dcf07168b58d8a04b46b82b24b65a0fc (patch)
treef67dc002b54ad707641275dfd51cb6662d2f720f
parent4b69cf6345341d71626b0aad91a91ab7debfbd7c (diff)
downloadperl6-matrix-client-b8b88f99dcf07168b58d8a04b46b82b24b65a0fc.tar.gz
Encode just the params for the request
-rw-r--r--lib/Matrix/Client/Requester.pm622
1 files changed, 15 insertions, 7 deletions
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))