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

Fix response headers from lint #2414

Merged
merged 8 commits into from
Jan 22, 2024

Conversation

ericproulx
Copy link
Contributor

@ericproulx ericproulx commented Jan 21, 2024

Fix #2411

Changes:

  • Use Rack::Utils.escape_html instead of ERB::Util.escape_html
  • Some refactor in error middleware.
  • Remove rack_response from inside_route
  • Remove some irrelevant if: ActiveSupport::VERSION::MAJOR >= ? in specs

@ericproulx ericproulx marked this pull request as ready for review January 21, 2024 13:36
Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

So we do have specs that use rack_response in rescue_from. Someone is undoubtedly relying on it.

  1. Add a section to UPGRADING.md.
  2. Is there a way we can re-implement it after these changes and mark it deprecated instead?

Revert rack_response in inside_route with deprecation
Add spec
@ericproulx
Copy link
Contributor Author

So we do have specs that use rack_response in rescue_from. Someone is undoubtedly relying on it.

1. Add a section to UPGRADING.md.

2. Is there a way we can re-implement it after these changes and mark it deprecated instead?

error_response has been removed also. It's an old deprecation from 0.12

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

nits, fix if you agree and hit merge

UPGRADING.md Outdated
@@ -3,6 +3,9 @@ Upgrading Grape

### Upgrading to >= 2.1.0

#### Changes in rescue_from
`rack_response` has been deprecated and `error_response` has been removed. Use `error!` instead.
Copy link
Member

Choose a reason for hiding this comment

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

The rack_response method ... (just to make it a sentence)

Link to the PR here and a couple missing below.

See [#2414](https://github.com/ruby-grape/grape/pull/2414) for more information.

@@ -180,8 +180,9 @@ def error!(message, status = nil, additional_headers = nil)
# A Rack::Response object containing the specified message, status, and headers.
#
def rack_response(message, status = 200, headers = { Rack::CONTENT_TYPE => content_type })
message = ERB::Util.html_escape(message) if headers[Rack::CONTENT_TYPE] == 'text/html'
Rack::Response.new([message], Rack::Utils.status_code(status), headers)
Grape.deprecator.warn('Use error! instead of rack_response')
Copy link
Member

Choose a reason for hiding this comment

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

I think this reads cleaner?

The rack_response method has been deprecated, use error! instead.

Change deprecation msg
@dblock dblock merged commit c6ad84a into ruby-grape:master Jan 22, 2024
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants