Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Simple Http Server
Manage
Activity
Members
Labels
Plan
Issues
0
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
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
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
many-archive
Simple Http Server
Commits
8dbfdb16
There was an error fetching the commit references. Please try again later.
Unverified
Commit
8dbfdb16
authored
6 years ago
by
LinFeng Qian
Committed by
GitHub
6 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #31 from Avi-D-coder/master
Redirect
parents
30738b90
81a2354f
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main.rs
+17
-1
17 additions, 1 deletion
src/main.rs
with
17 additions
and
1 deletion
src/main.rs
+
17
−
1
View file @
8dbfdb16
...
...
@@ -3,13 +3,13 @@ extern crate clap;
#[macro_use]
extern
crate
lazy_static
;
extern
crate
chrono
;
extern
crate
mime_guess
as
mime_types
;
extern
crate
filetime
;
extern
crate
flate2
;
extern
crate
htmlescape
;
extern
crate
hyper_native_tls
;
extern
crate
iron
;
extern
crate
iron_cors
;
extern
crate
mime_guess
as
mime_types
;
extern
crate
multipart
;
extern
crate
pretty_bytes
;
extern
crate
termcolor
;
...
...
@@ -84,6 +84,10 @@ fn main() {
.short
(
"u"
)
.long
(
"upload"
)
.help
(
"Enable upload files (multiple select)"
))
.arg
(
clap
::
Arg
::
with_name
(
"redirect"
)
.long
(
"redirect"
)
.takes_value
(
true
)
.validator
(|
url_string
|
iron
::
Url
::
parse
(
url_string
.as_str
())
.map
(|
_
|
()))
.help
(
"takes a URL to redirect to using the http 301"
))
.arg
(
clap
::
Arg
::
with_name
(
"nosort"
)
.long
(
"nosort"
)
.help
(
"Disable directory entries sort (by: name, modified, size)"
))
...
...
@@ -204,6 +208,10 @@ fn main() {
.unwrap_or_else
(||
env
::
current_dir
()
.unwrap
());
let
index
=
matches
.is_present
(
"index"
);
let
upload
=
matches
.is_present
(
"upload"
);
let
redirect_to
=
matches
.value_of
(
"redirect"
)
.map
(
iron
::
Url
::
parse
)
.map
(
Result
::
unwrap
);
let
sort
=
!
matches
.is_present
(
"nosort"
);
let
cache
=
!
matches
.is_present
(
"nocache"
);
let
range
=
!
matches
.is_present
(
"norange"
);
...
...
@@ -271,6 +279,7 @@ fn main() {
upload
,
cache
,
range
,
redirect_to
,
sort
,
compress
:
compress
.clone
()
...
...
@@ -323,6 +332,7 @@ struct MainHandler {
upload
:
bool
,
cache
:
bool
,
range
:
bool
,
redirect_to
:
Option
<
iron
::
Url
>
,
sort
:
bool
,
compress
:
Option
<
Vec
<
String
>>
,
try_file_404
:
Option
<
PathBuf
>
,
...
...
@@ -331,6 +341,12 @@ struct MainHandler {
impl
Handler
for
MainHandler
{
fn
handle
(
&
self
,
req
:
&
mut
Request
)
->
IronResult
<
Response
>
{
let
mut
fs_path
=
self
.root
.clone
();
if
let
Some
(
url
)
=
&
self
.redirect_to
{
return
Ok
(
Response
::
with
((
status
::
PermanentRedirect
,
Redirect
(
url
.clone
()),
)));
}
let
path_prefix
=
req
.url
.path
()
...
...
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