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

Add support for form data #59

Merged
merged 1 commit into from
Aug 20, 2020
Merged

Add support for form data #59

merged 1 commit into from
Aug 20, 2020

Conversation

JoelQ
Copy link
Contributor

@JoelQ JoelQ commented Aug 20, 2020

🧰 What's being changed?

According to HAR, data submitted with multipart/form-data or
application/x-www-form-urlencoded MIME types should be formatted as
key-value pairs under a request.postData.params key rather than the
request.postData.text key we use for other request types like JSON.

Additionally, we want to parse the data and filter out keys based on the
user's preferences.

🧪 Testing

Create a sample Rack app like:

# config.ru

$LOAD_PATH << File.expand_path("../path/to/metrics-sdks/packages/ruby/lib", __FILE__)
require "readme/metrics"

class ApiApp
  def call(env)
    [200, {"Content-Length" => "2"}, ["Ok"]]
  end
end

map "/api" do
  use Readme::Metrics, reject_params: ["reject"], buffer_length: 1, api_key: "YOUR_KEY_HERE" do
    { id: 1, label: "Joël", email: "[email protected]" }
  end
  run ApiApp.new
end

run it via:

$ rackup

and make a cURL request to it:

$ curl 'http://localhost:9292/api/foo' -X POST -d "reject=1&id=2&num=3"

Expect to see the request show up in the Readme dashboard with individual parameters. Also expect that the rejected parameter is filtered out.

ReadMe 2020-08-20 15-08-17

Contrast this with the way JSON requests come through as a single -d flag in the generated cURL command:

ReadMe 2020-08-20 15-09-43

@@ -36,6 +41,10 @@ def postData
end
end

def form_encoded_body
Har::Collection.new(@filter, @request.parsed_form_data).to_a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

According to HAR, data submitted with `multipart/form-data` or
`application/x-www-form-urlencoded` MIME types should be formatted as
key-value pairs under a `request.postData.params` key rather than the
`request.postData.text` key we use for other request types like JSON.

Additionally, we want to parse the data and filter out keys based on the
user's preferences.
@JoelQ JoelQ merged commit 72b7a56 into master Aug 20, 2020
@JoelQ JoelQ deleted the jq-form-data branch August 20, 2020 20:32
djmango pushed a commit to djmango/metrics-sdks that referenced this pull request Sep 19, 2023
Bumps [jest](https://github.com/facebook/jest) from 25.2.4 to 25.2.7.
- [Release notes](https://github.com/facebook/jest/releases)
- [Changelog](https://github.com/facebook/jest/blob/master/CHANGELOG.md)
- [Commits](jestjs/jest@v25.2.4...v25.2.7)

Signed-off-by: dependabot-preview[bot] <[email protected]>

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
@erunion erunion added ruby Issues related to our Ruby SDK and removed area:ruby labels Jul 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ruby Issues related to our Ruby SDK
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants