Coder Social home page Coder Social logo

perl6-http-client's People

Contributors

alexdaniel avatar gfldex avatar jj avatar moritz avatar perljedi avatar retupmoca avatar robertlemmen avatar supernovus avatar szabgab avatar zostay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

perl6-http-client's Issues

Consider a more Perl 6'ish API?

Did you consider letting the API exploit some of the shiny elegant Perl 6 features like assignable (rw) accessors and overloadable subscript operators?

This seems so Perl 5'ish to me:

$request.url('http://example.com/web/service');
$request.add-field(id => 37271);

Whereas Perl 6 allows the following, which would be a much more elegant I think:

$request.url = 'http://example.com/web/service';
$request.fields<id> = 37271;

Installation error

URLs are now outdated...

[HTTP::Client] Failed to resolve host name 'http.perl6.org' with family 0.

Can't upload binary data

Trying to upload a binary encoded file currently fails due to a bug in lib/HTTP/Client/Request.pm6 on line 218. The error given is

Cannot use a Buf as a string, but you called the Stringy method on it

The code I used to call it was as follows:

$request.add-file(
	:name($distname),
	:filename($distname),
	:type("application/gzip")
	:content($dist.IO.slurp(:bin))
	:binary
);

I've discussed this in #perl6 for a bit, and gotten some information there. It might be helpful to you.

right, but it's concatenating the supplied binary data (the POST's content) and a final CRLF into a Str. which will treat it as Unicode in NFG and do things like trying to normalize it

yeh, it's building an http request in a Str. I'd argue that's wrong from the very start; it should be using a buf8, any Str-s put into it should be encoded as specified by encoding headers or otherwise .. pedantically ought to reject but practically likely needs to use iso8859-1

Content inaccessible

Any attempt to access the contents of an HTTP Response results in a crash, with an exception being thrown.

Exception:

Nominal type check failed for parameter '$str'; expected Str but got Array instead
in sub unbase at gen/parrot/CORE.setting:6833
in block at lib/HTTP/Client/Response.pm6:113
in method dechunk at lib/HTTP/Client/Response.pm6:106
in method contents at lib/HTTP/Client/Response.pm6:140
in method content at lib/HTTP/Client/Response.pm6:146
in block at test.p6:7

Full source being used to test:
1 use v6;
2 use HTTP::Client;
3
4 my $client = HTTP::Client.new;
5 my $response = $client.get('http://www.whatismyip.com/');
6 if $response.success {
7 say $response.content;
8 }

No HTTPS support

It seems like it does not support https. The error I'm getting is pretty straightforward:

Unsupported protocol, 'https'.

Such a pity!

For those who are wondering if there is any other way, try HTTP::UserAgent or LWP::Simple.

does POST rather than PUT

diff --git a/lib/HTTP/Client.pm6 b/lib/HTTP/Client.pm6
index 2161fd5..87d7948 100644
--- a/lib/HTTP/Client.pm6
+++ b/lib/HTTP/Client.pm6
@@ -52,10 +52,10 @@ method simple-request ($method, $url?, :%query, :$follow) {
 method data-request 
 ($method, $url?, :%query, :%data, :%files, :$multipart, :$follow) {
   if ($url) {
-    my $req = self.make-request('POST', $url, :%query, :%data, :%files, :$multipart);
+    my $req = self.make-request($method, $url, :%query, :%data, :%files, :$multipart);
     return self.do-request($req, :$follow);
   }
-  self.make-request('POST', :$multipart); ## Only multipart option is used.
+  self.make-request($method, :$multipart); ## Only multipart option is used.
 }
 
 ## GET request

URI reparsing

Hi

I'm tracking progress of 2.0 version (to use it later in JSON::RPC::Client as you suggested) and I see that current version has the same performance issue as LWP::Simple - it is parsing URL on every request. In most API services URL is constant and only body changes between calls, so reparsing URL is a waste of CPU.

My idea is to allow passing URI object to Request object to skip parsing. Either by adding uri( ) method or overloading url( ) method.

For example:

multi method url ( URI $uri ) 
{
  $!uri = $uri;
  my $authbit = $!uri.grammar.parse_result<URI_reference><URI><authority>;
  if $authbit<userinfo>
   ... # rest of current url method
}

multi method url ( Str $url ) {
    self.url( URI.new( $url ) )
}

HTTP::Client test errors

Without running the internal HTTP::Easy example, i cannot depend on HTTP::Client. Could you explain what the issue you are having with rakudo perl6? I want to use HTTP::Client for https://github.com/azawawi/farabi6/

Even if i install HTTP::Client without executing any tests, i still get "Failed to get $url":

use HTTP::Client;
my $client = HTTP::Client.new;
my $url = 'http://google.com';
my $response = $client.get($url);
if ($response.success) {
        say "Got the following: $url";
} else {
        say "Failed while getting $url";
}

Rakuify

Change references of Perl 6 to Raku

Problem with chunked content

The following program called mine returns the following error :

Type check failed in binding $str; expected 'Str' but got 'Array'
in sub unbase at src/gen/m-CORE.setting:6857
in block at lib/HTTP/Client/Response.pm6:113
in method dechunk at lib/HTTP/Client/Response.pm6:106
in method contents at lib/HTTP/Client/Response.pm6:140
in method content at lib/HTTP/Client/Response.pm6:146
in sub slurp at mine:9
in block at mine:15

use HTTP::Client;
proto sub slurp(|) { * }

multi sub slurp($filename, :$bin = False, :$enc = 'utf8') {
if $filename.index: '://' -> $i {

require HTTP::Client;

   my $client = HTTP::Client.new;
   my $response = $client.get($filename);
   return  $response.content if $response.success ;
   fail;
} 
$filename.IO.slurp(:$bin, :$enc);

}
say slurp("http://paris.mongueurs.net");

For info, the page acceded with wget with the header printed

wget -S mongueurs.net
--2014-06-16 11:48:03-- http://mongueurs.net/
Resolving mongueurs.net... 91.216.186.189
Connecting to mongueurs.net|91.216.186.189|:80... connected.
HTTP request sent, awaiting response...
HTTP/1.1 200 OK
Server: Apache/1.3.42 (Unix)
Last-Modified: Mon, 16 Jun 2014 09:45:05 GMT
ETag: "1bc3f8b-3e95-539ebca1"
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Date: Mon, 16 Jun 2014 09:48:01 GMT
X-Varnish: 768907453
Age: 0
Via: 1.1 varnish
Connection: keep-alive
Length: unspecified [text/html]
Saving to: ‘index.html.2’

[  <=>                                  ] 16,021      70.7KB/s   in 0.2s   

2014-06-16 11:48:04 (70.7 KB/s) - ‘index.html.’ saved [16021]

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.