Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hikaru
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TO
hikaru
Commits
fe1bf0cd
Verified
Commit
fe1bf0cd
authored
6 years ago
by
jan.hamal.dvorak
Browse files
Options
Downloads
Patches
Plain Diff
Add referrer support
Signed-off-by:
Jan Hamal Dvořák
<
mordae@anilinux.org
>
parent
b017ece7
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/Web/Hikaru/Action.hs
+29
-0
29 additions, 0 deletions
lib/Web/Hikaru/Action.hs
with
29 additions
and
0 deletions
lib/Web/Hikaru/Action.hs
+
29
−
0
View file @
fe1bf0cd
...
...
@@ -19,6 +19,7 @@ module Web.Hikaru.Action
,
getMethod
,
getHeaders
,
getHeaderMaybe
,
getHeaderDefault
,
getAccept
,
getAcceptCharset
,
getAcceptEncoding
...
...
@@ -33,6 +34,7 @@ module Web.Hikaru.Action
,
getCookies
,
getCookieMaybe
,
getCookieDefault
,
getReferrer
,
getBodyLength
,
setBodyLimit
,
getBodyLimit
...
...
@@ -63,6 +65,7 @@ module Web.Hikaru.Action
,
sendString
,
sendJSON
,
redirect
,
redirectBack
,
setResponseFile
,
setResponseBuilder
,
setResponseBS
...
...
@@ -270,6 +273,14 @@ where
getHeaderMaybe
n
=
lookup
n
<$>
getHeaders
-- |
-- Obtain a specific request header or the given default value.
--
getHeaderDefault
::
(
MonadAction
m
)
=>
HeaderName
->
ByteString
->
m
ByteString
getHeaderDefault
n
v
=
fromMaybe
v
<$>
getHeaderMaybe
n
-- |
-- Obtain the Accept header value or the default value of @\"*/*\"@.
--
...
...
@@ -393,6 +404,17 @@ where
getCookieDefault
n
v
=
fromMaybe
v
<$>
getCookieMaybe
n
-- |
-- Returns HTTP @Referrer@ header or just @/@.
--
-- Useful for redirects back to where the user came from.
--
getReferrer
::
(
MonadAction
m
)
=>
m
Text
getReferrer
=
do
header
<-
getHeaderDefault
hReferer
"/"
return
(
cs
header
)
-- |
-- Try to obtain request body length.
-- This will fail when the body is chunked.
...
...
@@ -854,6 +876,13 @@ where
setHeader
hLocation
(
cs
location
)
-- |
-- Redirect the user to where he came from using 'getReferrer'.
--
redirectBack
::
(
MonadAction
m
)
=>
m
()
redirectBack
=
redirect
=<<
getReferrer
-- |
-- Create response body using a file.
--
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment