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
e40abea4
Commit
e40abea4
authored
1 year ago
by
codecraft
Browse files
Options
Downloads
Patches
Plain Diff
Reading in body of requests with body
parent
3eca9706
No related branches found
Branches containing commit
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
+46
-9
46 additions, 9 deletions
core/http/src/handlers/handlers.rs
core/http/src/handling/request.rs
+9
-0
9 additions, 0 deletions
core/http/src/handling/request.rs
with
55 additions
and
9 deletions
core/http/src/handlers/handlers.rs
+
46
−
9
View file @
e40abea4
use
std
::{
use
std
::{
io
::{
BufRead
,
BufReader
,
Write
},
io
::{
BufRead
,
BufReader
,
Read
,
Write
},
net
::
TcpStream
,
net
::
TcpStream
,
path
::
PathBuf
,
path
::
PathBuf
,
};
};
...
@@ -13,12 +13,20 @@ use crate::handling::{
...
@@ -13,12 +13,20 @@ use crate::handling::{
use
crate
::
setup
::
MountPoint
;
use
crate
::
setup
::
MountPoint
;
pub
fn
handle_connection
(
mut
stream
:
TcpStream
,
mountpoints
:
Vec
<
MountPoint
>
)
{
pub
fn
handle_connection
(
mut
stream
:
TcpStream
,
mountpoints
:
Vec
<
MountPoint
>
)
{
let
buf_reader
=
BufReader
::
new
(
&
mut
stream
);
let
mut
buf_reader
=
BufReader
::
new
(
&
mut
stream
);
let
http_request
:
Vec
<
String
>
=
buf_reader
let
mut
http_request
:
Vec
<
String
>
=
vec!
[];
.lines
()
.map
(|
result
|
result
.unwrap
())
loop
{
.take_while
(|
line
|
!
line
.is_empty
())
let
mut
buffer
=
String
::
new
();
.collect
();
let
_
=
buf_reader
.read_line
(
&
mut
buffer
)
.unwrap
();
if
buffer
==
"
\r\n
"
{
break
;
}
http_request
.push
(
buffer
);
}
println!
(
"{:#?}"
,
http_request
);
let
request_status_line
=
http_request
.get
(
0
);
let
request_status_line
=
http_request
.get
(
0
);
if
request_status_line
==
None
{
if
request_status_line
==
None
{
return
;
return
;
...
@@ -35,10 +43,39 @@ pub fn handle_connection(mut stream: TcpStream, mountpoints: Vec<MountPoint>) {
...
@@ -35,10 +43,39 @@ pub fn handle_connection(mut stream: TcpStream, mountpoints: Vec<MountPoint>) {
.unwrap
(),
.unwrap
(),
};
};
let
data
=
Data
{
let
mut
data
=
Data
{
is_complete
:
false
,
buffer
:
vec!
[],
buffer
:
vec!
[],
is_complete
:
true
,
};
};
if
request
.can_have_body
()
{
let
length
=
if
let
Some
(
len
)
=
request
.headers
.iter
()
.filter
(|
header
|
header
.contains
(
"Content-Length: "
))
.clone
()
.map
(|
header
|
{
let
header
=
header
.strip_prefix
(
"Content-Length: "
)
.unwrap
();
header
.trim
()
.parse
::
<
usize
>
()
})
.next
()
{
if
let
Ok
(
size
)
=
len
{
size
}
else
{
0
}
}
else
{
0
};
let
mut
buffer
:
Vec
<
u8
>
=
vec!
[
0
;
length
];
let
read_len
=
buf_reader
.read
(
&
mut
buffer
)
.unwrap
();
if
read_len
!=
length
{
eprintln!
(
"User inputted invalid BUFLEN"
);
return
;
}
data
.is_complete
=
true
;
data
.buffer
=
buffer
;
}
let
mut
handled_response
:
Option
<
Outcome
<
Response
,
Status
,
Data
>>
=
None
;
let
mut
handled_response
:
Option
<
Outcome
<
Response
,
Status
,
Data
>>
=
None
;
for
mountpoint
in
mountpoints
{
for
mountpoint
in
mountpoints
{
...
...
This diff is collapsed.
Click to expand it.
core/http/src/handling/request.rs
+
9
−
0
View file @
e40abea4
...
@@ -22,3 +22,12 @@ pub enum MediaType {
...
@@ -22,3 +22,12 @@ pub enum MediaType {
Plain
,
Plain
,
Html
,
Html
,
}
}
impl
Request
<
'_
>
{
pub
fn
can_have_body
(
&
self
)
->
bool
{
match
self
.method
{
Method
::
Post
|
Method
::
Put
|
Method
::
Patch
|
Method
::
Delete
=>
true
,
_
=>
false
,
}
}
}
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