Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
rust-swerve
Manage
Activity
Members
Labels
Plan
Issues
4
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container 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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Louis
rust-swerve
Commits
023ae3c6
Unverified
Commit
023ae3c6
authored
7 years ago
by
Louis
Browse files
Options
Downloads
Patches
Plain Diff
Add fairing to perform internal redirect when encountering a script path
parent
6ef64fbf
No related branches found
No related tags found
1 merge request
!2
Scripting
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/routing/mod.rs
+4
-0
4 additions, 0 deletions
src/routing/mod.rs
src/routing/request_rewriter.rs
+56
-0
56 additions, 0 deletions
src/routing/request_rewriter.rs
with
60 additions
and
0 deletions
src/routing/mod.rs
+
4
−
0
View file @
023ae3c6
...
@@ -2,3 +2,7 @@ pub mod mock_upload;
...
@@ -2,3 +2,7 @@ pub mod mock_upload;
pub
mod
request
;
pub
mod
request
;
pub
mod
scripting
;
pub
mod
scripting
;
pub
mod
core
;
pub
mod
core
;
mod
request_rewriter
;
pub
use
self
::
request_rewriter
::{
ScriptMap
,
RedirectScripts
};
This diff is collapsed.
Click to expand it.
src/routing/request_rewriter.rs
0 → 100644
+
56
−
0
View file @
023ae3c6
use
rocket
::
fairing
::{
Fairing
,
Info
,
Kind
};
use
rocket
::{
Request
,
Data
,
Rocket
,
State
};
use
cli
::
SwerveConfig
;
use
std
::
collections
::
HashMap
;
use
routing
::
request
::
path
::
MatchablePath
;
pub
struct
ScriptMap
(
pub
HashMap
<
MatchablePath
,
String
>
);
impl
ScriptMap
{
pub
fn
from_config
(
conf
:
&
SwerveConfig
)
->
Self
{
let
mut
map
:
HashMap
<
MatchablePath
,
String
>
=
HashMap
::
new
();
for
handler
in
&
conf
.routes
{
if
let
Some
(
ref
script
)
=
handler
.script
{
map
.insert
(
MatchablePath
::
from
(
handler
.route
.clone
()),
script
.clone
());
}
}
ScriptMap
(
map
)
}
}
pub
struct
RedirectScripts
;
impl
Fairing
for
RedirectScripts
{
fn
info
(
&
self
)
->
Info
{
Info
{
name
:
"Redirect Scripts To Handler"
,
kind
:
Kind
::
Request
,
}
}
fn
on_request
(
&
self
,
request
:
&
mut
Request
,
_
:
&
Data
)
{
let
script_map_container
=
request
.guard
::
<
State
<
ScriptMap
>>
()
.unwrap
();
let
script_map
:
&
HashMap
<
MatchablePath
,
String
>
=
&
script_map_container
.0
;
for
path
in
script_map
.keys
()
{
let
matches
=
path
.matches
(
request
.uri
()
.path
());
if
let
Some
(
values
)
=
matches
{
let
script_name
=
script_map
.get
(
path
)
.unwrap
();
let
mut
value_buffer
=
String
::
new
();
value_buffer
.push_str
(
"script_path="
);
value_buffer
.push_str
(
script_name
);
for
(
ref
param
,
ref
val
)
in
values
{
value_buffer
.push_str
(
"&"
);
value_buffer
.push_str
(
param
);
value_buffer
.push_str
(
"="
);
value_buffer
.push_str
(
val
);
}
let
path
=
format!
(
"/__run_script__/?{}"
,
value_buffer
);
request
.set_uri
(
path
);
break
;
}
}
}
}
\ No newline at end of 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