Commit Graph

54 Commits

Author SHA1 Message Date
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
Sebastien Boeuf
a730d86940 Receive multiple file descriptors with a Request
Extending the existing code to support receiving more than one file
descriptor per request. The micro-http crate might be used in a context
where multiple file descriptors are associated with one request, hence
the need to update the micro-http crate.

A concrete example from Cloud Hypervisor is to be able to pass multiple
TAP file descriptors at once when adding a new network interface. This
way it can hotplug a multiqueue device.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2022-01-28 19:30:22 +02:00
George Pisaltu
0a58eb1ece added support for Deprecation header
This commit adds support for the `Deprecation` HTTP header based on
https://tools.ietf.org/id/draft-dalal-deprecation-header-03.html .
Users can set this header in a `Response` to send a
"Deprecation: true" header field back to the requester, signaling
that the resource accessed has been deprecated.

Signed-off-by: George Pisaltu <gpl@amazon.com>
2021-10-19 20:37:52 +03:00
AlexandruCihodaru
51923caf61 Add optional limit on request size
Signed-off-by: AlexandruCihodaru <cihodar@amazon.com>
2021-09-03 13:56:22 +03:00
AlexandruCihodaru
ba4e5a0917 Added payload too large response
Signed-off-by: AlexandruCihodaru <cihodar@amazon.com>
Suggested-by: George Pisaltu <gpl@amazon.com>
2021-09-03 13:56:22 +03:00
Luminita Voicu
c1a38b507c response: add Unauthorized status code
Signed-off-by: Luminita Voicu <lumivo@amazon.com>
2021-08-09 17:18:31 +03:00
Sebastien Boeuf
9517a30037 Retrieve the optional file associated with a Request
The sever is now able to get any optional file descriptor that might
have been sent over with the bytes related to a request. This patch
leverages this ability by extending the Request structure with an
optional File, which might have been received from the byte stream.

With the Request containing an optional File, we give the consumers of
this crate the possibility to receive a file descriptor associated with
the HTTP request.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
2021-07-14 16:42:48 +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
03c7869d43 add custom headers support
Signed-off-by: Luminita Voicu <lumivo@amazon.com>
2021-07-09 11:32:22 +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
Luminita Voicu
83dcfdd22b reorder Http errors
Signed-off-by: Luminita Voicu <lumivo@amazon.com>
2021-07-09 11:32:22 +03:00
Luminita Voicu
a5fdf928eb response: minor comment fixes
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
49240ce1d5 Add unit tests to raise coverage score
Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
2021-04-15 11:21:32 +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
Gulshan Kumar
67fd749e03 Removed Unnecessary pub
Signed-off-by: Gulshan Kumar <kumargu@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
Alexandra Iordache
88de0ed16b micro-http: unsigned Content-Length...
...and a bunch of fixes for unchecked unsigned arithmetic
in connection.rs. Added more unit tests too that exercise
failure cases for over/underflows in mathematic operations.

Fixes #1977

Signed-off-by: Alexandra Iordache <aghecen@amazon.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
moricho
9830b66a09 dumbo: remove dumbo's dependency on mmds
This moves dumbo::ns to mmds crate and
implements response retrieval callback passed to dumbo's tcp::handler

Signed-off-by: moricho <ikeda.morito@gmail.com>
Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
2021-04-15 11:21:32 +03:00
wt-l00
c5a3f9f543 Add more flexibility when parsing the headers
Any number of whitespace characters are accepted after ":"
when parsing HTTP headers.
Create a test function (Add test_parse_header_whitespace).
This test addresses parsing header and allow no space and
any amount of linear white space after ":". And modified
CHANGELOG.md.

Signed-off-by: Eisuke Matsushita <ei13suke@gmail.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
Iulian Barbu
d37f9671af micro-http: added MethodNotAllow status code
When server returns `Method Not Allow` responses,
it can attach to the response a HTTP `Allow` header.
Added support for HTTP response `Allow` header as
well.

Signed-off-by: Iulian Barbu <iul@amazon.com>
Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
2021-04-15 11:21:32 +03:00
Iulian Barbu
530b36bfd9 micro_http: add support for accept headers
Signed-off-by: Iulian Barbu <iul@amazon.com>
Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
2021-04-15 11:21:32 +03:00
iulianbarbu
4a25226f2a mmds: added support for custom ipv4 address
Added a new API for configuring MMDS. At the moment,
this configuration applies only for the MMDS IPv4 address.

Besides the new API, this commits comprises changes to the
NetBuilder implementation and usages.

Signed-off-by: iulianbarbu <iul@amazon.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
Popa
7eb11b44cb clean-up: get rid of misplaced cfg(test)
Signed-off-by: Popa <dpopa@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
keyangxie
7289d64e24 micro_http: update unit test
Add some test cases for uri test, to cover sub-domain uri
and `ip:port`.

Refactor `test_uri` and `test_find`. Leverage tupled vector
to init test inputs and expected values, and remove superfluous
lines. It will be more flexible to modify the test cases.

Signed-off-by: keyangxie <keyang.xie@gmail.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
Bob Potter
4ee7142098 micro_http: adjust match on header fields
Use case-insensitive check since some http clients use lower case
headers.

Signed-off-by: Bob Potter <bobby.potter@gmail.com>
Signed-off-by: YUAN LYU <lyuyuan92@gmail.com>
2021-04-15 11:21:32 +03:00
Changwei Ge
59ab64440a Add http status code 503
When we are not capable to provide a certain kind of service, but should be
after some delay. Http server is better to reply status code 503. It is more
suggestive per as to http spec.

```
The server is currently unable to handle the request due to a temporary
overload or scheduled maintenance, which will likely be alleviated after some delay.
```

Signed-off-by: Changwei Ge <chge@linux.alibaba.com>
2020-11-03 08:38:02 +02: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
c9ffb90aeb Handle ErrorKind::Interrupted when doing stream IO
When doing IO with the underlying stream object, we should handle
the special case of ErrorKind::Interrupted, otherwise the connection
will be closed incorrectly.

Quotation from Rust doc:
An error of the [`ErrorKind::Interrupted`] kind is non-fatal and the
read operation should be retried if there is nothing else to do.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2020-04-27 09:41:16 +03:00
Liu Jiang
0d87a94c8e Route request according to {method, path} tuple
Route request according to {method, path} tuple, so we could use only
one router for each http server.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2020-03-30 13:52:34 +03:00
Liu Jiang
8ca0839b58 Simplify the HttpRoute trait
Previously the HttpRoute has logic to clone the handler parameter,
which is an implementation detail of the API server. So simplify
the HttpRoute interfaces by removing the argument cloning logic.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2020-03-30 13:52:34 +03:00
Liu Jiang
ac3bb940ab Import http routes from Cloud Hypervisor project
Import vmm/src/api/http.rs from Cloud Hyerpvisor project, commit
345c922cb9a88183e2da9d29230ecb945b0a6452 with following changes:
1) use generic type for handler argument.
2) remove server thread relative code.
3) add unit test cases.
4) refine for better code reuse.

Signed-off-by: Liu Jiang <gerry@linux.alibaba.com>
2020-03-30 13:52:34 +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