5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-17 07:26:23 +00:00

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
# 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
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
# Los navegadores antiguos no envían Origin