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:
parent
5c36de818f
commit
6b67f13aaf
1 changed files with 23 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue