Skip to content

How to build a request without running it? #421

Closed

Description

@hmistry

There are 2 things I'd like to do with this library and not sure how to do it.

First, I'd like to print out the request to see if everything looks correct. I'm thinking something like HTTP.headers(some_hash).get(some_url).to_s which will create a string something like GET some_url headers: some_headers. With this I don't need to waste time with MiTM apps and can see the conversion is correct.

Second, I'd like to build a request without executing it. How can I do this? I couldn't find it in your docs/code. The reason is I need to create a signature token based on the request headers + body (it's for AWS). Having this ability would greatly simplify coding.

#  (pseudo code for idea - ignore syntax correctness)
# current
headers = { some: values }
payload = something
content_size = payload.size
uri = some_url_with_params
signature = calculate_signature(headers.merge(content-length: content_size), payload, host_uri, params)
res = HTTP.headers(headers.merge(Authorization: signature).get(uri)

# my wish
request = HTTP.headers( some: values).build_request(:get, uri, { body: payload })
response = request.headers(Authorization: calculate_signature(request)).run

Hope this makes sense.

Activity

  1. ixti commented on Jul 21, 2017

    @ixti
    Member

    Logging interactions will be possible soon - I'm gonna find time next week to merge down outstanding PRs including logging one.

    I like the proposal of build_request in fact I was thinking about that lately, as I needed the same for myself. Thus I'm totally open for PRs or will do that myself once will have some spare moments.

  2. rwehresmann commented on Apr 17, 2018

    @rwehresmann

    Any news about that?

  3. tycooon commented on Apr 17, 2018

    @tycooon

    HTTP::Client#build_request method has been added to master recently (see https://github.com/httprb/http/pull/458/files).

  4. rwehresmann commented on Apr 17, 2018

    @rwehresmann

    The example of the issue should work? I'm trying:

    HTTP.headers({ accept: 'text/html' }).build_request('get', URI('https://www.google.ccom'))
    
    NoMethodError: undefined method `build_request' for #<HTTP::Client:0x007f0904858338>
  5. tycooon commented on Apr 17, 2018

    @tycooon

    Are you sure that you are using the version from master? It's not released on rubygems I guess.

  6. rwehresmann commented on Apr 17, 2018

    @rwehresmann

    You're right, I didn't noticed that It wasn't in rubygems (: Tks!

  7. janko commented on Nov 18, 2018

    @janko
    Member

    This has been implemented in #458.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions