Origin y Referer
Algunos navegadores no envían Origin, la forma de obtenerlo es mirar en el Referer.
This commit is contained in:
parent
5c36de818f
commit
6b67f13aaf
1 changed files with 23 additions and 1 deletions
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue