Commit Graph

29 Commits

Author SHA1 Message Date
Patrick Roy
ef43cef716 chore: appease clippy
Fix clippy lints now triggered due to upgraded rust toolchain

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
2024-02-22 11:41:58 +00:00
acatangiu
73f37d0797 Impl PartialEq on ServerError for tests
Co-authored-by: acatangiu <adrian@parity.io>
Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
2023-08-24 17:56:59 +01:00
acatangiu
3c5d9407d3 Add kill switch functionality
Added shutdown event-fd acting as a kill switch actionable from
outside the micro-http server.

Needed to be able to break out of the inner epoll_wait on demand.

This can be used to signal the micro-http server running on a
dedicated thread that it needs to shut down.

Co-authored-by: acatangiu <adrian.catangiu@gmail.com>
Signed-off-by: Egor Lazarchuk <yegorlz@amazon.co.uk>
2023-08-24 17:56:59 +01:00
Patrick Roy
43d5a1d4b0 Clear all clippy warnings
Additionally, HttpServer::new_from_fd has been marked as unsafe,
since the correctness of the unsafe call within the function
relies on the caller upholding an invariant

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
2022-11-22 12:15:22 +02:00
Patrick Roy
d2caafab0e Run cargo fmt
The CI requirements for formatting have changed over the past 3 years

Signed-off-by: Patrick Roy <roypat@amazon.co.uk>
2022-11-22 12:15:22 +02:00
AlexandruCihodaru
51923caf61 Add optional limit on request size
Signed-off-by: AlexandruCihodaru <cihodar@amazon.com>
2021-09-03 13:56:22 +03:00
Sebastien Boeuf
3c4cc3aa91 Expect stream to implement ScmSocket trait
The stream used by the Connection structure is expected to implement
both Read and Write traits. Since we want the server to be able to
receive file descriptors through control messages mechanism, this patch
extends the expectations regarding the stream by adding ScmSocket to the
list of traits.

Since the stream is a UnixStream structure, and since vmm-sys-util
already provides an ScmSocket implementation for UnixStream, extending
the list of traits is very straightforward.

Relying on the newly added trait, the server now reads incoming bytes
through recv_with_fd() function, which replaces the former call to
read(). This change has no intent of modifying the former behavior from
the read(), which is why the returned Option<File> is ignored for now.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-07-14 16:42:48 +03:00
Luminita Voicu
eb8b8cb53d Add optional limit on request size
Signed-off-by: Luminita Voicu <lumivo@amazon.com>
2021-07-09 11:32:22 +03:00
Luminita Voicu
7f3a14f16f forbid GET requests with body content
Signed-off-by: Luminita Voicu <lumivo@amazon.com>
2021-07-09 11:32:22 +03:00
William Douglas
9b605a8b61 Enable creating a socket from an existing fd
Allow the creation of the http server's socket from an existing
fd. This is done to enable another process to initiate the creation of
a server by preparing the socket so it can immediately be used rather
than polling to connect to the path.

Note, the coverage file change due to what appears to be a rounding
error when calculating coverage.

Signed-off-by: William Douglas <william.douglas@intel.com>
2021-04-20 11:15:44 +03:00
YUAN LYU
9e6ab4b5ab Clean up after cherry-picking commits from firecracker
Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
2021-04-15 11:21:32 +03:00
George Pisaltu
e73f412536 micro-http: explicit HUP/ERR handling in server
The server in `micro_http` was not explicitly handling the `EPOLLHUP`,
`EPOLLRDHUP` and `EPOLLERR` epoll events. Added new checks that close
a connection that is signaled with these events.

Signed-off-by: George Pisaltu <gpl@amazon.com>
Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
2021-04-15 11:21:32 +03:00
berciuliviu
ed44e2af6f Add error handling for fatal errors
This commit adds a mechanism that considers
some errors as 'fatal'. It alerts the user and then
terminates the Firecracker process.

Signed-off-by: berciuliviu <lberciu@amazon.com>
Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
2021-04-15 11:21:32 +03:00
Alexandru Cihodaru
683b85d07e Added support for Accept-Encoding
Signed-off-by: Alexandru Cihodaru <cihodar@amazon.com>
Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
2021-04-15 11:21:32 +03:00
cihodar
8a8d7bb5b1 Made InvalidHeader error more verbose.
Changed the way we handle TransferEncoding
and added new test cases.

Signed-off-by: cihodar <cihodar@amazon.com>
Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
2021-04-15 11:21:32 +03:00
Damien Stanton
eeae4ac11d Remove all extern crate...
In Rust 2018 edition, it is considered unidiomatic to use "extern crate"
sunthax. The proper way to do it is to replace extern crate with "use"
declarations.

- Also impl clippy suggestions for fn main removal in doctests
- Fix unneeded box allocations and clones

Signed-off-by: Damien Stanton <damien.stanton@gmail.com>
Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
2021-04-15 11:21:32 +03:00
Damien Stanton
a7f035b8c5 micro_http: switch to rust edition 2018
Signed-off-by: Damien Stanton <damien.stanton@gmail.com>
Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
2021-04-15 11:21:32 +03:00
defunct
48b8f179c8 use epoll implementation from vmm-sys-util
Signed-off-by: defunct <defunct@defunct.io>
Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
2021-04-15 11:21:32 +03:00
Ioana Chirca
17ead39d82 micro_http: check arithmetic operations
Signed-off-by: Ioana Chirca <chioana@amazon.com>
Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
2021-04-15 11:21:32 +03:00
timvisee
3e888638e5 Implement clippy suggestions for Rust 1.43.1
Signed-off-by: timvisee <tim@visee.me>
Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
2021-04-15 11:21:32 +03:00
Shion Yamashita
2e3f629054 micro_http: fix name of helper function in tests
Signed-off-by: Shion Yamashita <shioyama1118@gmail.com>
Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
2021-04-15 11:21:32 +03:00
Shion Yamashita
d7a7bd0fe2 Use TempFile when generating path to socket
Signed-off-by: Shion Yamashita <shioyama1118@gmail.com>
Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
2021-04-15 11:21:32 +03:00
Adrian Catangiu
d288940391 micro_http: gracefully handle EINTR
EINTR errors should not break the HttpServer requests loop,
they are internally consumed and reported as no events rather
than requests errors.

Signed-off-by: Adrian Catangiu <acatan@amazon.com>
Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
2021-04-15 11:21:32 +03:00
Laura Loghin
548d297be7 Completely remove epoll crate dependency
Move epoll.rs from polly to utils crate and use this file,
in micro_http, as an epoll wrapper instead of the epoll crate.

Signed-off-by: Laura Loghin <lauralg@amazon.com>
Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
2021-04-15 11:21:32 +03:00
karthik nedunchezhiyan
569230220f micro_http: some doc and code corrections
Signed-off-by: karthik nedunchezhiyan <karthik1705.n@gmail.com>
Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
2021-04-15 11:21:32 +03:00
Adrian Catangiu
c33861a13b Handle ErrorKind::Interrupted when waiting for events
ErrorKind::Interrupted (libc::EINTR) errors should not break the
HttpServer requests loop, they are internally consumed and reported
as no events rather than requests errors.

Signed-off-by: Adrian Catangiu <acatan@amazon.com>
2020-07-23 18:17:33 +03:00
Liu Jiang
31bc6268c7 Unregister fd from epoll_fd when closing a connection
When closing a http connection, the corresponding file descriptor
should be unregistered from the epoll fd.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2020-03-30 13:52:34 +03:00
Liu Jiang
fbb4d5392a Refine code for rust edition 2018
Refine code to support rust edition 2018, no functional changes.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2020-03-30 13:52:34 +03:00
Andreea Florescu
6708271862 initial commit
Pulled the code from firecracker-microvm/src/micro-http.

Signed-off-by: George Pisaltu <gpl@amazon.com>
Signed-off-by: Andreea Florescu <fandree@amazon.com>
2020-01-27 12:28:50 +02:00