Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Before handle request method #273

Merged
merged 4 commits into from
Oct 27, 2019
Merged

Before handle request method #273

merged 4 commits into from
Oct 27, 2019

Conversation

le0pard
Copy link
Contributor

@le0pard le0pard commented Sep 9, 2019

Hello.

I have feature proposal, which very valuable for my use cases. My proposal to add new config variable before_handle_request, which provide ability to define method to normalize, filter, cleanup request before pass it to handlers. Use cases:

Filter sensitive information before store to cache store

If you request from JS code contain some sensitive information, you can remove them or repalce to some dump info by this example

c.before_handle_request = proc { |method, url, headers, body|
  filtered_body = JSON.stringify(replace_secret_data(JSON.parse(body)))
  [method, url, headers, filtered_body]
}

Normalize POST body before store to cache and fetch from cache

Some libs, like braintree.js generate for each request UUID and add this info POST body. This doesn't allow to reuse the same stored cache, because cache key and comparison based on body content. This function allow to replace this dynamic info inside POST body (normalization):

c.before_handle_request = proc { |method, url, headers, body|
  [method, url, headers, normalize_body(body)]
}

@le0pard
Copy link
Contributor Author

le0pard commented Sep 9, 2019

Looks like capybara-webkit cannot build on CI :(

@ronwsmith
Copy link
Collaborator

@le0pard Thanks for the contribution! If you are able to fix the CI issue, please feel free, or I will in a couple weeks when I have time.

@le0pard
Copy link
Contributor Author

le0pard commented Sep 10, 2019

@ronwsmith hope this will increase speed to accept my PR :)

P.S. You can ask Travis CI support to migrate this repo from travis-ci.org to travis-ci.com - https://docs.travis-ci.com/user/migrate/open-source-repository-migration

@ronwsmith
Copy link
Collaborator

@le0pard Awesome, thanks! I'll try to get it in this weekend when I'm back home.

@le0pard
Copy link
Contributor Author

le0pard commented Oct 21, 2019

@ronwsmith hello. How are you? You like disappear from github...

@ronwsmith
Copy link
Collaborator

I'm back @le0pard, thanks for your patience!

@ronwsmith ronwsmith merged commit c6cfc3b into oesmith:master Oct 27, 2019
@ronwsmith ronwsmith mentioned this pull request Oct 27, 2019
@ronwsmith
Copy link
Collaborator

Released in v2.2.0

@le0pard
Copy link
Contributor Author

le0pard commented Oct 27, 2019

Big thanks @ronwsmith

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants