Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Injecting a value into HTTP::Header

by 1nickt (Canon)
on Apr 19, 2021 at 11:34 UTC ( [id://11131468]=note: print w/replies, xml ) Need Help??


in reply to Injecting a value into HTTP::Header

Hi, "not managing to get the injection to work" doesn't really describe the problem well. What is the output? I assume there's an error with push_header() since that does not appear as a documented method on an HTTP::Response object. Try https://metacpan.org/pod/HTTP::Response#$r-%3Eheader(-$field-=%3E-$value-).

Hope this helps!



The way forward always starts with a minimal test.

Replies are listed 'Best First'.
Re^2: Injecting a value into HTTP::Header
by Bod (Parson) on Apr 19, 2021 at 16:31 UTC
    Hope this helps!

    It helped immensely thank you...
    It forced me to go and find where I had got push_header() from. In doing that search of source code it twigged that it was not the header that needed token_type but the content. With that realisation, the rest sort of fell into place.

    Here is the working overridden sub in case anyone has a similar problem and comes across this in future:

    sub construct_tokens { my ($self, $oauth2, $response) = @_; my $content = eval {decode_json($response->content)}; unless ($@) { $content->{'token_type'} = 'bearer'; $response->content(encode_json($content)); } $self->SUPER::construct_tokens($oauth2, $response); }

    Can anyone explain what the documentation means when is says to contribute one should submit a git pull request? I would like to contribute my LinkedIn solution when it is complete and tested as I am sure I am not the only person wanting to connect to LinkedIn with Perl.

        you need to fork the GitHub repository and create a pull request

        That's the bit I'm not sure what I'm doing...
        But I guess the starting point is to create a GitHub account and go from there.

Re^2: Injecting a value into HTTP::Header
by Bod (Parson) on Apr 19, 2021 at 12:51 UTC
    Hi, "not managing to get the injection to work" doesn't really describe the problem well

    Sorry - yes, re-reading my question shows it is not very clear.

    What I meant was that injecting the token_type parameter is not working. My sub doesn't throw an error but causes the super class sub to throw an error that token_type is missing.

    push_header() since that does not appear as a documented method on an HTTP::Response object

    HTTP::Response extends HTTP::Message which requires's HTTP::Headers and push_header() is a method of this class.

    Although looking at the link you provided sparked the realisation that token_type is not a header at all. It needs to be added to the content rather than the header. So I think I am going to have to decode the JSON content to a Perl data structure, add the token_type parameter before encoding it back to JSON and passing that to the super class' sub.

    I can see running into propblems with the encoding as there doesn't appear to be a way to reverse the effects of decoded_content

      Never mnind, sry, not enough coffee.

      You misunderstand how the inheritance works. See the doc I linked to and run some minimal tests.


      The way forward always starts with a minimal test.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11131468]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (4)
As of 2024-03-28 16:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found