Origin y Referer

Algunos navegadores no envían Origin, la forma de obtenerlo es mirar en
el Referer.
This commit is contained in:
f 2021-07-29 10:53:54 -03:00
parent 5c36de818f
commit 6b67f13aaf

View file

@ -23,8 +23,30 @@ module Api
end end
end end
# Referer
#
# @see {https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referer}
# @return [String,Nil]
def referer
request.referer
end
alias referrer referer
# Origin
#
# @see {https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Origin}
# @return [String,Nil]
def origin def origin
request.headers['Origin'] request.origin
end
# Genera un header Origin a partir del Referer si existe.
#
# @return [String,Nil]
def origin_from_referer
return if referer.blank?
referer.split('/', 4).tap { |u| u.pop if u.size > 3 }.join('/')
end end
# Los navegadores antiguos no envían Origin # Los navegadores antiguos no envían Origin