Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
W
WebServer
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor 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
codecraft
WebServer
Commits
21a170df
Commit
21a170df
authored
1 year ago
by
codecraft
Browse files
Options
Downloads
Patches
Plain Diff
Add HEAD Method support
parent
2b30adc7
Branches
main
No related tags found
1 merge request
!1
Initial feature merge
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
core/http/src/handlers/handlers.rs
+8
-3
8 additions, 3 deletions
core/http/src/handlers/handlers.rs
site/src/main.rs
+7
-2
7 additions, 2 deletions
site/src/main.rs
with
15 additions
and
5 deletions
core/http/src/handlers/handlers.rs
+
8
−
3
View file @
21a170df
...
...
@@ -6,7 +6,7 @@ use crate::handling::{
file_handlers
::
NamedFile
,
request
::
Request
,
response
::{
Outcome
,
Response
,
ResponseBody
,
Status
},
routes
::
Data
,
routes
::
Data
,
methods
::
Method
,
};
use
crate
::
setup
::
MountPoint
;
...
...
@@ -103,7 +103,8 @@ pub async fn handle_connection(mut stream: TcpStream, mountpoints: Vec<MountPoin
}
let
mounted_request_uri
=
request
.uri
.strip_prefix
(
mountpoint
.mountpoint
)
.unwrap
();
for
route
in
mountpoint
.routes
{
if
route
.method
!=
request
.method
{
if
(
route
.method
!=
request
.method
)
&&
((
route
.method
!=
Method
::
Get
)
&&
(
request
.method
==
Method
::
Head
))
{
continue
;
}
if
!
route
.compare_uri
(
mounted_request_uri
)
{
...
...
@@ -130,7 +131,11 @@ pub async fn handle_connection(mut stream: TcpStream, mountpoints: Vec<MountPoin
format!
(
"HTTP/1.1 {}
\r\n
"
,
success
.status
.unwrap_or
(
Status
::
Ok
))
+
&
success
.headers
.join
(
"
\r\n
"
)
+
"
\r\n\r\n
"
,
success
.body
.get_data
(),
if
request
.method
==
Method
::
Head
{
vec!
[]
}
else
{
success
.body
.get_data
()
}
),
Outcome
::
Failure
(
error
)
=>
failure_handler
(
error
),
Outcome
::
Forward
(
_
)
=>
failure_handler
(
Status
::
NotFound
),
...
...
This diff is collapsed.
Click to expand it.
site/src/main.rs
+
7
−
2
View file @
21a170df
...
...
@@ -20,8 +20,13 @@ fn hashmap_to_string(map: &HashMap<&str, &str>) -> String {
result
}
fn
handle_static_hi
(
request
:
Request
<
'_
>
,
_data
:
Data
)
->
Outcome
<
Response
,
Status
,
Data
>
{
let
response
=
hashmap_to_string
(
&
request
.get_form_keys
(
vec!
[
"asdf"
,
"jkj"
])
.unwrap
());
fn
handle_static_hi
(
request
:
Request
<
'_
>
,
data
:
Data
)
->
Outcome
<
Response
,
Status
,
Data
>
{
let
keys
=
if
let
Ok
(
keys
)
=
request
.get_form_keys
(
vec!
[
"asdf"
,
"jkl;"
])
{
keys
}
else
{
return
Outcome
::
Forward
(
data
);
};
let
response
=
hashmap_to_string
(
&
keys
);
Outcome
::
Success
(
Response
{
headers
:
vec!
[
format!
(
"Content-Length: {}"
,
response
.len
()),
...
...
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