Skip Menu |

This queue is for tickets about the REST-Client CPAN distribution.

Report information
The Basics
Id: 119790
Status: open
Priority: 0/
Queue: REST-Client

People
Owner: Nobody in particular
Requestors: GNUSTAVO [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 273
Fixed in: (no value)



Subject: Allow the default host be superseded by absolute URLs
Hi. I'm the author of JIRA::REST and a few other modules that depend on REST::Client. Thank you for your time saver module! My modules usually create a REST::Client object passing to it a default host to make it easier to interact with the server using relative URLs. However, sometimes the result of a REST method contains absolute URLs referencing related resources and it would be useful to be able to use them as is in subsequent requests. As a concrete example, I'm using JIRA's REST API to grok a project's roles using this method: https://docs.atlassian.com/jira/REST/server/#api/2/project/{projectIdOrKey}/role-getProjectRoles. JIRA::REST's API allows the user to pass only the "/rest/api/2/project/{projectIdOrKey}/role" method path. However, the method's result contain absolute URLs like this: Show quoted text
Currently I have to remove the "http://www.example.com/jira" prefix from them before passing them to REST::Client::GET because the method REST::Client::_prepareURL always prefix the URL with the default host, even if it gets an absolute URL. It would be very convenient if it could leave absolute URLs intact, using the default host only to prefix relative URLs. What do you think? I'm attaching a patch that can be applied to v273 to implement this. BTW, do you have a public repository for REST::Client? Thanks!
Subject: rest-client.patch
diff --git a/lib/REST/Client.pm b/lib/REST/Client.pm index fa35fec..6e77723 100644 --- a/lib/REST/Client.pm +++ b/lib/REST/Client.pm @@ -102,8 +102,8 @@ The config flags are: =item host -A default host that will be prepended to all requests. Allows you to just -specify the path when making requests. +A default host that will be prepended to all requests using relative URLs. +Allows you to just specify the path when making requests. The default is undef - you must include the host in your requests. @@ -476,6 +476,9 @@ sub _prepareURL { my $self = shift; my $url = shift; + # Do not prepend default host to absolute URLs. + return $url if $url =~ /^https?:/; + my $host = $self->getHost; if($host){ $url = '/'.$url unless $url =~ /^\//;
Subject: Re: [rt.cpan.org #119790] Allow the default host be superseded by absolute URLs
Date: Tue, 10 Jan 2017 13:27:26 -0500
To: bug-REST-Client [...] rt.cpan.org
From: "Kevin L. Kane" <kevin.kane [...] gmail.com>
Hi Gustavo, We are using https://github.com/milescrawford/cpan-rest-client as the authoritative place for REST::Client. I like the idea of your patch, let me know if you want me apply it/commit it or you want to fork on github and create a pull request either way fine with me. Thanks, Kevin On Tue, Jan 10, 2017 at 12:57 PM, Gustavo Leite de Mendonça Chaves via RT < bug-REST-Client@rt.cpan.org> wrote: Show quoted text
> Tue Jan 10 12:57:40 2017: Request 119790 was acted upon. > Transaction: Ticket created by GNUSTAVO > Queue: REST-Client > Subject: Allow the default host be superseded by absolute URLs > Broken in: 273 > Severity: (no value) > Owner: Nobody > Requestors: GNUSTAVO@cpan.org > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=119790 > > > > Hi. I'm the author of JIRA::REST and a few other modules that depend on > REST::Client. Thank you for your time saver module! > > My modules usually create a REST::Client object passing to it a default > host to make it easier to interact with the server using relative URLs. > However, sometimes the result of a REST method contains absolute URLs > referencing related resources and it would be useful to be able to use them > as is in subsequent requests. > > As a concrete example, I'm using JIRA's REST API to grok a project's roles > using this method: https://docs.atlassian.com/jira/REST/server/#api/2/ > project/{projectIdOrKey}/role-getProjectRoles. > > JIRA::REST's API allows the user to pass only the "/rest/api/2/project/{projectIdOrKey}/role" > method path. However, the method's result contain absolute URLs like this: >
> > { > > "Administrators": "http://www.example.com/jira/
> rest/api/2/project/MKY/role/10002", > 10001",
> > "Developers": "http://www.example.com/jira/
> rest/api/2/project/MKY/role/10000"
> > }
> > Currently I have to remove the "http://www.example.com/jira" prefix from > them before passing them to REST::Client::GET because the method > REST::Client::_prepareURL always prefix the URL with the default host, even > if it gets an absolute URL. > > It would be very convenient if it could leave absolute URLs intact, using > the default host only to prefix relative URLs. > > What do you think? > > I'm attaching a patch that can be applied to v273 to implement this. > > BTW, do you have a public repository for REST::Client? > > Thanks! >
-- Kevin L. Kane kevin.kane at gmail.com
Subject: Re: [rt.cpan.org #119790] Allow the default host be superseded by absolute URLs
Date: Tue, 10 Jan 2017 16:48:24 -0200
To: bug-REST-Client [...] rt.cpan.org
From: Gustavo Leite de Mendonça Chaves <gnustavo [...] cpan.org>
Great! I'll fork it and submit a pull request in a moment. Thanks! 2017-01-10 16:27 GMT-02:00 Kevin L. Kane via RT <bug-REST-Client@rt.cpan.org Show quoted text
>:
Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=119790 > > > Hi Gustavo, > We are using https://github.com/milescrawford/cpan-rest-client as the > authoritative place for REST::Client. I like the idea of your patch, let > me know if you want me apply it/commit it or you want to fork on github and > create a pull request either way fine with me. > > Thanks, > Kevin > > On Tue, Jan 10, 2017 at 12:57 PM, Gustavo Leite de Mendonça Chaves via RT < > bug-REST-Client@rt.cpan.org> wrote: >
> > Tue Jan 10 12:57:40 2017: Request 119790 was acted upon. > > Transaction: Ticket created by GNUSTAVO > > Queue: REST-Client > > Subject: Allow the default host be superseded by absolute URLs > > Broken in: 273 > > Severity: (no value) > > Owner: Nobody > > Requestors: GNUSTAVO@cpan.org > > Status: new > > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=119790 > > > > > > > Hi. I'm the author of JIRA::REST and a few other modules that depend on > > REST::Client. Thank you for your time saver module! > > > > My modules usually create a REST::Client object passing to it a default > > host to make it easier to interact with the server using relative URLs. > > However, sometimes the result of a REST method contains absolute URLs > > referencing related resources and it would be useful to be able to use
> them
> > as is in subsequent requests. > > > > As a concrete example, I'm using JIRA's REST API to grok a project's
> roles
> > using this method: https://docs.atlassian.com/jira/REST/server/#api/2/ > > project/{projectIdOrKey}/role-getProjectRoles. > > > > JIRA::REST's API allows the user to pass only the "/rest/api/2/project/{
> projectIdOrKey}/role"
> > method path. However, the method's result contain absolute URLs like
> this:
> >
> > > { > > > "Administrators": "http://www.example.com/jira/
> > rest/api/2/project/MKY/role/10002", > > 10001",
> > > "Developers": "http://www.example.com/jira/
> > rest/api/2/project/MKY/role/10000"
> > > }
> > > > Currently I have to remove the "http://www.example.com/jira" prefix from > > them before passing them to REST::Client::GET because the method > > REST::Client::_prepareURL always prefix the URL with the default host,
> even
> > if it gets an absolute URL. > > > > It would be very convenient if it could leave absolute URLs intact, using > > the default host only to prefix relative URLs. > > > > What do you think? > > > > I'm attaching a patch that can be applied to v273 to implement this. > > > > BTW, do you have a public repository for REST::Client? > > > > Thanks! > >
> > > > -- > Kevin L. Kane > kevin.kane at gmail.com >