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

Set HTTP GET body to nil, resolves #56 #57

Merged
merged 1 commit into from
Jan 16, 2024
Merged

Set HTTP GET body to nil, resolves #56 #57

merged 1 commit into from
Jan 16, 2024

Conversation

ag-TJNII
Copy link
Contributor

@ag-TJNII ag-TJNII commented Jan 16, 2024

Tested in our client app which reads the schedules and users endpoints.

# The run_request() method body argument defaults to {}, which is incorrect for GET requests
# https://github.com/technicalpickles/pager_duty-connection/issues/56
# NOTE: PagerDuty support discourages GET requests with bodies, but not throwing an ArgumentError to prevent breaking
# corner-case implementations.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd love to do a logger.warn here as I think a raise(ArgumentError) would be too aggressive and potentially breaking, but I don't think we have a logger. I see some logging in the Faraday setup but I don't think that's easily usable. Let me know if there is a logger or if we're okay throwing an ArgumentError if someone tries to do a HTTP GET request with a body.

Copy link
Owner

Choose a reason for hiding this comment

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

We have activesupport as a dependency, so we could use it's deprecation support for it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Neat. I think I might have to leave that to someone else as I'm more of a pure Rubyist, so I have little experience with the Rails Active Library ecosystem. While that Deprecation system looks simple on the surface I'm not clear on exactly which deprecation method is needed to deprecate an argument to a method. I see ActiveSupport::Deprecation also needs a gem version, which I assume would be 3.0? Might be best if I leave this to someone who knows their way around better.

Copy link
Owner

@technicalpickles technicalpickles left a comment

Choose a reason for hiding this comment

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

Thanks for debugging and putting this together!

This change looks good, just had one suggestion. I suggested activesupport deprecation for tracking the behavior change, but that can be a followup work.

# The run_request() method body argument defaults to {}, which is incorrect for GET requests
# https://github.com/technicalpickles/pager_duty-connection/issues/56
# NOTE: PagerDuty support discourages GET requests with bodies, but not throwing an ArgumentError to prevent breaking
# corner-case implementations.
Copy link
Owner

Choose a reason for hiding this comment

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

We have activesupport as a dependency, so we could use it's deprecation support for it.

Comment on lines +70 to +74
unless body.nil?
TIME_KEYS.each do |key|
if body.has_key?(key)
body[key] = body[key].iso8601 if body[key].respond_to?(:iso8601)
end
Copy link
Owner

Choose a reason for hiding this comment

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

This middleware is very narrowly scoped, so think it is just as easy, and more readable, to have a guard clause to return early:

Suggested change
unless body.nil?
TIME_KEYS.each do |key|
if body.has_key?(key)
body[key] = body[key].iso8601 if body[key].respond_to?(:iso8601)
end
return unless body
TIME_KEYS.each do |key|
if body.has_key?(key)
body[key] = body[key].iso8601 if body[key].respond_to?(:iso8601)
end

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will skip the @app.call on line 78. That's why I didn't use a guard clause, as I didn't want to duplicate that line of code. Is that @app.call env line safe to skip in this case? I'm not familiar with Faraday Middleware.

Copy link
Owner

Choose a reason for hiding this comment

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

Ah, right you are. I missed that at the bottom of the method. I still like guard clauses, but that can be a followup. Going to merge to be able to release this.

Comment on lines +70 to +74
unless body.nil?
TIME_KEYS.each do |key|
if body.has_key?(key)
body[key] = body[key].iso8601 if body[key].respond_to?(:iso8601)
end
Copy link
Owner

Choose a reason for hiding this comment

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

Ah, right you are. I missed that at the bottom of the method. I still like guard clauses, but that can be a followup. Going to merge to be able to release this.

@technicalpickles technicalpickles merged commit 8b2b3ab into technicalpickles:master Jan 16, 2024
@technicalpickles technicalpickles mentioned this pull request Jan 16, 2024
@ag-TJNII ag-TJNII deleted the TJNII-Get-Body branch January 16, 2024 18:48
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.

None yet

2 participants