Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
bwinf
medal
Commits
c6e67f89
Commit
c6e67f89
authored
Feb 08, 2019
by
Robert Czechowski
Browse files
Distribute cookies whenever there are none set
parent
0350caab
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/webfw_iron.rs
View file @
c6e67f89
...
...
@@ -77,6 +77,29 @@ impl iron_sessionstorage::Value for SessionToken {
}
use
::
iron
::
middleware
::{
AroundMiddleware
,
Handler
};
use
rand
::{
thread_rng
,
Rng
,
distributions
::
Alphanumeric
};
pub
struct
CookieDistributor
{}
impl
CookieDistributor
{
pub
fn
new
()
->
Self
{
Self
{}
}
}
impl
AroundMiddleware
for
CookieDistributor
{
fn
around
(
self
,
handler
:
Box
<
Handler
>
)
->
Box
<
Handler
>
{
Box
::
new
(
move
|
req
:
&
mut
Request
|
->
IronResult
<
Response
>
{
if
!
req
.session
()
.get
::
<
SessionToken
>
()
.expect
(
"blub..."
)
.is_some
()
{
let
session_token
:
String
=
thread_rng
()
.sample_iter
(
&
Alphanumeric
)
.take
(
10
)
.collect
();
req
.session
()
.set
(
SessionToken
{
token
:
session_token
})
.unwrap
();
}
handler
.handle
(
req
)
})
}
}
#[derive(Debug)]
struct
SessionError
{
message
:
String
...
...
@@ -861,6 +884,7 @@ pub fn start_server(conn: Connection, config: ::Config) -> iron::error::HttpResu
ch
.link
(
Write
::
<
SharedDatabaseConnection
>
::
both
(
conn
));
ch
.link
(
Write
::
<
SharedConfiguration
>
::
both
(
config
.clone
()));
ch
.link_around
(
CookieDistributor
::
new
());
ch
.link_around
(
SessionStorage
::
new
(
SignedCookieBackend
::
new
(
my_secret
)));
...
...
Robert Czechowski
@zgtm
mentioned in issue
#3 (closed)
·
Feb 08, 2019
mentioned in issue
#3 (closed)
mentioned in issue #3
Toggle commit list
Robert Czechowski
@zgtm
mentioned in issue
#121
·
Nov 12, 2020
mentioned in issue
#121
mentioned in issue #121
Toggle commit list
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment