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
add79a72
There was an error fetching the commit references. Please try again later.
Commit
add79a72
authored
2 years ago
by
Linfeng Qian
Browse files
Options
Downloads
Patches
Plain Diff
fix clippy
parent
10328afe
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
+9
-27
9 additions, 27 deletions
src/main.rs
with
9 additions
and
27 deletions
src/main.rs
+
9
−
27
View file @
add79a72
...
@@ -23,7 +23,6 @@ use iron_cors::CorsMiddleware;
...
@@ -23,7 +23,6 @@ use iron_cors::CorsMiddleware;
use
lazy_static
::
lazy_static
;
use
lazy_static
::
lazy_static
;
use
mime_guess
as
mime_types
;
use
mime_guess
as
mime_types
;
use
multipart
::
server
::{
Multipart
,
SaveResult
};
use
multipart
::
server
::{
Multipart
,
SaveResult
};
use
open
;
use
path_dedot
::
ParseDot
;
use
path_dedot
::
ParseDot
;
use
percent_encoding
::
percent_decode
;
use
percent_encoding
::
percent_decode
;
use
pretty_bytes
::
converter
::
convert
;
use
pretty_bytes
::
converter
::
convert
;
...
@@ -265,7 +264,7 @@ fn main() {
...
@@ -265,7 +264,7 @@ fn main() {
match
open
::
that
(
&
host
)
{
match
open
::
that
(
&
host
)
{
Ok
(
_
)
=>
println!
(
"Openning {} in default browser"
,
&
host
),
Ok
(
_
)
=>
println!
(
"Openning {} in default browser"
,
&
host
),
Err
(
err
)
=>
eprintln!
(
"Unable to open in default browser {}"
,
err
.to_string
()
),
Err
(
err
)
=>
eprintln!
(
"Unable to open in default browser {}"
,
err
),
}
}
}
}
...
@@ -510,11 +509,7 @@ impl Handler for MainHandler {
...
@@ -510,11 +509,7 @@ impl Handler for MainHandler {
}
}
impl
MainHandler
{
impl
MainHandler
{
fn
save_files
(
fn
save_files
(
&
self
,
req
:
&
mut
Request
,
path
:
&
Path
)
->
Result
<
(),
(
status
::
Status
,
String
)
>
{
&
self
,
req
:
&
mut
Request
,
path
:
&
PathBuf
,
)
->
Result
<
(),
(
status
::
Status
,
String
)
>
{
match
Multipart
::
from_request
(
req
)
{
match
Multipart
::
from_request
(
req
)
{
Ok
(
mut
multipart
)
=>
{
Ok
(
mut
multipart
)
=>
{
// Fetching all data and processing it.
// Fetching all data and processing it.
...
@@ -566,7 +561,7 @@ impl MainHandler {
...
@@ -566,7 +561,7 @@ impl MainHandler {
for
field
in
files_fields
{
for
field
in
files_fields
{
let
mut
data
=
field
.data
.readable
()
.unwrap
();
let
mut
data
=
field
.data
.readable
()
.unwrap
();
let
headers
=
&
field
.headers
;
let
headers
=
&
field
.headers
;
let
mut
target_path
=
path
.
clo
ne
();
let
mut
target_path
=
path
.
to_ow
ne
d
();
target_path
.push
(
headers
.filename
.clone
()
.unwrap
());
target_path
.push
(
headers
.filename
.clone
()
.unwrap
());
if
let
Err
(
errno
)
=
std
::
fs
::
File
::
create
(
target_path
)
if
let
Err
(
errno
)
=
std
::
fs
::
File
::
create
(
target_path
)
...
@@ -600,7 +595,7 @@ impl MainHandler {
...
@@ -600,7 +595,7 @@ impl MainHandler {
fn
list_directory
(
fn
list_directory
(
&
self
,
&
self
,
req
:
&
mut
Request
,
req
:
&
mut
Request
,
fs_path
:
&
Path
Buf
,
fs_path
:
&
Path
,
path_prefix
:
&
[
String
],
path_prefix
:
&
[
String
],
)
->
IronResult
<
Response
>
{
)
->
IronResult
<
Response
>
{
struct
Entry
{
struct
Entry
{
...
@@ -609,7 +604,7 @@ impl MainHandler {
...
@@ -609,7 +604,7 @@ impl MainHandler {
}
}
let
mut
resp
=
Response
::
with
(
status
::
Ok
);
let
mut
resp
=
Response
::
with
(
status
::
Ok
);
let
mut
fs_path
=
fs_path
.
clo
ne
();
let
mut
fs_path
=
fs_path
.
to_ow
ne
d
();
let
mut
rows
=
Vec
::
new
();
let
mut
rows
=
Vec
::
new
();
let
read_dir
=
fs
::
read_dir
(
&
fs_path
)
.map_err
(
error_io2iron
)
?
;
let
read_dir
=
fs
::
read_dir
(
&
fs_path
)
.map_err
(
error_io2iron
)
?
;
...
@@ -625,8 +620,7 @@ impl MainHandler {
...
@@ -625,8 +620,7 @@ impl MainHandler {
// Breadcrumb navigation
// Breadcrumb navigation
let
breadcrumb
=
if
!
path_prefix
.is_empty
()
{
let
breadcrumb
=
if
!
path_prefix
.is_empty
()
{
let
mut
breadcrumb
=
path_prefix
.to_owned
();
let
mut
breadcrumb
=
path_prefix
.to_owned
();
let
mut
bread_links
:
Vec
<
String
>
=
Vec
::
new
();
let
mut
bread_links
:
Vec
<
String
>
=
vec!
[
breadcrumb
.pop
()
.unwrap
()];
bread_links
.push
(
breadcrumb
.pop
()
.unwrap
());
while
!
breadcrumb
.is_empty
()
{
while
!
breadcrumb
.is_empty
()
{
bread_links
.push
(
format!
(
bread_links
.push
(
format!
(
r#"<a href="/{link}/"><strong>{label}</strong></a>"#
,
r#"<a href="/{link}/"><strong>{label}</strong></a>"#
,
...
@@ -662,21 +656,13 @@ impl MainHandler {
...
@@ -662,21 +656,13 @@ impl MainHandler {
}
}
if
let
Some
(
field
)
=
sort_field
{
if
let
Some
(
field
)
=
sort_field
{
if
SORT_FIELDS
if
!
SORT_FIELDS
.iter
()
.any
(|
s
|
*
s
==
field
.as_str
())
{
.iter
()
.position
(|
s
|
*
s
==
field
.as_str
())
.is_none
()
{
return
Err
(
IronError
::
new
(
return
Err
(
IronError
::
new
(
StringError
(
format!
(
"Unknown sort field: {}"
,
field
)),
StringError
(
format!
(
"Unknown sort field: {}"
,
field
)),
status
::
BadRequest
,
status
::
BadRequest
,
));
));
}
}
if
vec!
[
ORDER_ASC
,
ORDER_DESC
]
if
!
[
ORDER_ASC
,
ORDER_DESC
]
.iter
()
.any
(|
s
|
*
s
==
order
)
{
.iter
()
.position
(|
s
|
*
s
==
order
)
.is_none
()
{
return
Err
(
IronError
::
new
(
return
Err
(
IronError
::
new
(
StringError
(
format!
(
"Unknown sort order: {}"
,
order
)),
StringError
(
format!
(
"Unknown sort order: {}"
,
order
)),
status
::
BadRequest
,
status
::
BadRequest
,
...
@@ -929,11 +915,7 @@ impl MainHandler {
...
@@ -929,11 +915,7 @@ impl MainHandler {
// [Reference]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match
// [Reference]: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Match
// Check header::If-Match
// Check header::If-Match
if
let
Some
(
&
IfMatch
::
Items
(
ref
items
))
=
req
.headers.get
::
<
IfMatch
>
()
{
if
let
Some
(
&
IfMatch
::
Items
(
ref
items
))
=
req
.headers.get
::
<
IfMatch
>
()
{
if
items
if
!
items
.iter
()
.any
(|
item
|
item
.strong_eq
(
&
etag
))
{
.iter
()
.position
(|
item
|
item
.strong_eq
(
&
etag
))
.is_none
()
{
return
Err
(
IronError
::
new
(
return
Err
(
IronError
::
new
(
StringError
(
"Etag not matched"
.to_owned
()),
StringError
(
"Etag not matched"
.to_owned
()),
status
::
RangeNotSatisfiable
,
status
::
RangeNotSatisfiable
,
...
...
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