Optional %headers and $content params support. #3

Merged
merged 1 commit into from Apr 14, 2011

Conversation

Projects
None yet
3 participants

bbkr commented Apr 13, 2011

Added HTTP Request optional %headers and $content params to get() method, so various *RPC clients can be implemented using this module.

Confirmed by new test that calls live JSON-PRC demo service.

bbkr Added HTTP Request %headers and $content params to get() method, so v…
…arious *RPC clients can be implemented using this module
6d5db65
Contributor

tadzik commented Apr 13, 2011

Good job!
Would you mind adding some docs to the get() params? Also, given the $content parameter isn't it more like post() now? I may be wrong, that'd be due to the lack of docs :)

bbkr commented Apr 13, 2011

Let me answer get/post question:

POST and GET are HTTP methods which both can have headers and content, RFC 2616 9.3 and 9.5. Section 9.1.1 of this RFC explains differences. GET is considered "safe" method (which in perfect world should be synonym for "retrieval only") while POST means that possibly unsafe action is being requested.

It's up to server to decide about acceptance of GET request with content (like in RPC calls). RFC states clearly that in this case "user did not request the side-effects, so therefore cannot be held accountable for them".

So presence of Content does not mean you have to perform POST request.

As for module documentation - I plan to fix my JSON::RPC module now, and I will contribute to LWP::Simple docs right after that :)

@cosimo cosimo commented on the diff Apr 14, 2011

lib/LWP/Simple.pm
@@ -62,8 +60,16 @@ method get (Str $url) {
%headers<Host> = $hostname;
- my ($status, $resp_headers, $content) =
- self.make_request($hostname, $port, $path, %headers);
+ if ($content.defined) {
+ # Attach Content-Length header
+ # as recommended in RFC2616 section 14.3.
+ # Note: Empty content is also a content,
+ # header value equals to zero is valid.
+ %headers{'Content-Length'} = $content.bytes;
+ }
+
+ my ($status, $resp_headers, $resp_content) =
+ self.make_request($hostname, $port, $path, %headers, $content);
@cosimo

cosimo Apr 14, 2011

Owner

Would be cool to use named args here

@cosimo cosimo merged commit 6d5db65 into cosimo:master Apr 14, 2011

@jonathanstowe jonathanstowe added a commit to jonathanstowe/perl6-lwp-simple that referenced this pull request Sep 28, 2016

@jonathanstowe jonathanstowe Move the require IO::Socket::SSL away from mainline
fixes #3
1bd887d

@jonathanstowe jonathanstowe added a commit to jonathanstowe/perl6-lwp-simple that referenced this pull request Sep 28, 2016

@jonathanstowe jonathanstowe Add a test for issue #3 2aababe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment