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

Provide default values when Content-Length is absent #70

Merged
merged 1 commit into from
Aug 27, 2020

Conversation

thestrabusiness
Copy link
Contributor

@thestrabusiness thestrabusiness commented Aug 26, 2020

🧰 What's being changed?

The Content-Length header is not included by default starting in Rails
5. This commit adds some new functionality to the HttpResponse class
so that we can calculate the content length if the header is not present.

Commit that removes the middleware: rails/rails@5690358

🧪 Testing

Automated tests were added to cover this new behavior.

@JoelQ
Copy link
Contributor

JoelQ commented Aug 27, 2020

Based on the HAR spec, I think we want to put -1 if we don't know the length rather than 0

bodySize [number] - Size of the request body (POST data payload) in bytes. Set to -1 if the info is not available.

packages/ruby/README.md Outdated Show resolved Hide resolved
packages/ruby/lib/readme/har/response_serializer.rb Outdated Show resolved Hide resolved
packages/ruby/README.md Outdated Show resolved Hide resolved
packages/ruby/lib/http_response.rb Outdated Show resolved Hide resolved
packages/ruby/lib/http_response.rb Show resolved Hide resolved
packages/ruby/spec/http_response_spec.rb Outdated Show resolved Hide resolved
packages/ruby/spec/http_response_spec.rb Outdated Show resolved Hide resolved
packages/ruby/spec/http_response_spec.rb Outdated Show resolved Hide resolved
packages/ruby/spec/readme/har/response_serializer_spec.rb Outdated Show resolved Hide resolved
packages/ruby/spec/readme/har/response_serializer_spec.rb Outdated Show resolved Hide resolved
packages/ruby/spec/readme/har/response_serializer_spec.rb Outdated Show resolved Hide resolved
Copy link
Contributor

@JoelQ JoelQ left a comment

Choose a reason for hiding this comment

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

Couple small suggestions, otherwise LGTM

expect(response.body).to eq ""
end

it "returns an empty string when the body is an array of string" do
Copy link
Contributor

Choose a reason for hiding this comment

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

The doc string is wrong here, this isn't an empty string

response = HttpResponse.from_parts(
204,
{"Content-Length" => 53},
nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we put an actual body here so the test proves that it's the 204 status rather than the nil causing the 0?

The Content-Length header is not included by default starting in Rails
5. This commit adds a default -1 value for the `Har::ResponseSerializer`
   for values that rely on the Content-Length header when it is absent.

The instructions are also updated to mention the `Rack::ContentLength`
middleware users can add to their application if they'd like to see that
value in their ReadMe requests.
@thestrabusiness thestrabusiness merged commit f8978aa into master Aug 27, 2020
@thestrabusiness thestrabusiness deleted the am-default-content-length branch August 27, 2020 18:24
djmango pushed a commit to djmango/metrics-sdks that referenced this pull request Sep 19, 2023
…meio#70)

Bumps [@readme/eslint-config](https://github.com/readmeio/eslint-config) from 2.0.4 to 2.0.6.
- [Release notes](https://github.com/readmeio/eslint-config/releases)
- [Changelog](https://github.com/readmeio/eslint-config/blob/master/CHANGELOG.md)
- [Commits](readmeio/standards@2.0.4...2.0.6)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

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