How can I print out the raw request HTTP is sending?

82 views
Skip to first unread message

Christopher Peterson

unread,
Sep 11, 2018, 4:43:49 PM9/11/18
to http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
Hello,

I am trying to debug a really big pain of an End Point, it's the AWS Cognito Token End Point, so I'm wondering how I might print out the raw request that HTTP puts together to send out.

Any help would be greatly appreciated. I already burned a few days trying to use Net::HTTP.

I can get this thing to work over curl, so I know it's in how I'm sending.


Here's the working CURL command:
curl -d "grant_type=authorization_code&client_id=<my_client_id>&code=<code_given_by_cognito>&redirect_uri=<my_redirect_url>" -H "Content-Type: application/x-www-form-urlencoded" -X POST https://<my_domain>.auth.us-west-2.amazoncognito.com/oauth2/token

Here's my Ruby code:
ctx = OpenSSL::SSL::SSLContext.new
ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE

path = "https://<my_domain>.auth.us-west-2.amazoncognito.com/oauth2/token"

args = "grant_type=authorization_code&client_id=<my_client_id>&code=<
code_given_by_cognito>&redirect_uri=<my_redirect_url>"

response
= HTTP.headers(:content_type => "application/x-www-form-urlencoded").post(path, :body => args, :ssl_context => ctx)


Thanks!
Chris

Tony Arcieri

unread,
Sep 11, 2018, 4:56:08 PM9/11/18
to christophe...@marketingevolution.com, http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
If you're able to run http.rb master, we just merged a new event / observer system which is able to log requests and should hopefully address your needs:


Otherwise this is something of a longstanding issue. The latest synopsis is here:


--
You received this message because you are subscribed to the Google Groups "http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API" group.
To unsubscribe from this group and stop receiving emails from it, send an email to httprb+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Tony Arcieri

Christopher Peterson

unread,
Sep 11, 2018, 4:59:45 PM9/11/18
to http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
I totally can use master, do you know how to bundle install it? I'll try and look it up as well. :)

Tony Arcieri

unread,
Sep 11, 2018, 5:23:31 PM9/11/18
to christophe...@marketingevolution.com, http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
On Tue, Sep 11, 2018 at 1:59 PM Christopher Peterson <christophe...@marketingevolution.com> wrote:
I totally can use master, do you know how to bundle install it? I'll try and look it up as well. :)

Try the following in your Gemfile:

    gem "http", github: "httprb/http"
 
--
Tony Arcieri

Christopher Peterson

unread,
Sep 11, 2018, 5:25:50 PM9/11/18
to http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
Thanks! Well that was easier than what I just did of pulling the repo and build/installing it :)

Christopher Peterson

unread,
Sep 11, 2018, 5:49:59 PM9/11/18
to http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
Do you know why I might get unsupported feature? Do I need to do anything other than add that .use() to the command?

response
= HTTP.use(logging: {logger: Logger.new(STDOUT)}).headers(:content_type => "application/x-www-form-urlencoded").post(path, :body => args, :ssl_context => ctx)


I got:
HTTP::Error (Unsupported feature: logging):

Christopher Peterson

unread,
Sep 11, 2018, 5:59:58 PM9/11/18
to http.rb: a fast, easy-to-use Ruby HTTP client with a chainable API
Nevermind, user error :)
Reply all
Reply to author
Forward
0 new messages