Add Deprecation
headers on deprecated endpoints (#34262)
Co-authored-by: Damien Mathieu <42@dmathieu.com>
This commit is contained in:
parent
40bb8ec325
commit
38f5e74122
10 changed files with 121 additions and 12 deletions
17
app/controllers/concerns/deprecation_concern.rb
Normal file
17
app/controllers/concerns/deprecation_concern.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module DeprecationConcern
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
class_methods do
|
||||
def deprecate_api(date, sunset: nil, **kwargs)
|
||||
deprecation_timestamp = "@#{date.to_datetime.to_i}"
|
||||
sunset = sunset&.to_date&.httpdate
|
||||
|
||||
before_action(**kwargs) do
|
||||
response.headers['Deprecation'] = deprecation_timestamp
|
||||
response.headers['Sunset'] = sunset if sunset
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue