Skip to content

Commit 2d17054

Browse files
committed
change: async-h1 endpoints always return a response
1 parent b71e346 commit 2d17054

File tree

5 files changed

+19
-19
lines changed

5 files changed

+19
-19
lines changed

examples/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ async fn main() -> http_types::Result<()> {
2626
// Take a TCP stream, and convert it into sequential HTTP request / response pairs.
2727
async fn accept(stream: TcpStream) -> http_types::Result<()> {
2828
println!("starting new connection from {}", stream.peer_addr()?);
29-
async_h1::accept(stream.clone(), |_req| async move {
29+
async_h1::accept(stream, |_req| async move {
3030
let mut res = Response::new(StatusCode::Ok);
3131
res.insert_header("Content-Type", "text/plain");
3232
res.set_body("Hello world");
33-
Ok(res)
33+
res
3434
})
3535
.await?;
3636
Ok(())

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
//! let mut res = Response::new(StatusCode::Ok);
8282
//! res.insert_header("Content-Type", "text/plain");
8383
//! res.set_body("Hello");
84-
//! Ok(res)
84+
//! res
8585
//! })
8686
//! .await?;
8787
//! Ok(())

src/server/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub async fn accept<RW, F, Fut>(io: RW, endpoint: F) -> http_types::Result<()>
3535
where
3636
RW: Read + Write + Clone + Send + Sync + Unpin + 'static,
3737
F: Fn(Request) -> Fut,
38-
Fut: Future<Output = http_types::Result<Response>>,
38+
Fut: Future<Output = Response>,
3939
{
4040
Server::new(io, endpoint).accept().await
4141
}
@@ -51,7 +51,7 @@ pub async fn accept_with_opts<RW, F, Fut>(
5151
where
5252
RW: Read + Write + Clone + Send + Sync + Unpin + 'static,
5353
F: Fn(Request) -> Fut,
54-
Fut: Future<Output = http_types::Result<Response>>,
54+
Fut: Future<Output = Response>,
5555
{
5656
Server::new(io, endpoint).with_opts(opts).accept().await
5757
}
@@ -79,7 +79,7 @@ impl<RW, F, Fut> Server<RW, F, Fut>
7979
where
8080
RW: Read + Write + Clone + Send + Sync + Unpin + 'static,
8181
F: Fn(Request) -> Fut,
82-
Fut: Future<Output = http_types::Result<Response>>,
82+
Fut: Future<Output = Response>,
8383
{
8484
/// builds a new server
8585
pub fn new(io: RW, endpoint: F) -> Self {
@@ -108,7 +108,7 @@ where
108108
where
109109
RW: Read + Write + Clone + Send + Sync + Unpin + 'static,
110110
F: Fn(Request) -> Fut,
111-
Fut: Future<Output = http_types::Result<Response>>,
111+
Fut: Future<Output = Response>,
112112
{
113113
// Decode a new request, timing out if this takes longer than the timeout duration.
114114
let fut = decode(self.io.clone());
@@ -140,7 +140,7 @@ where
140140
let method = req.method();
141141

142142
// Pass the request to the endpoint and encode the response.
143-
let mut res = (self.endpoint)(req).await?;
143+
let mut res = (self.endpoint)(req).await;
144144

145145
close_connection |= res
146146
.header(CONNECTION)

tests/accept.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mod accept {
1111
let mut response = Response::new(200);
1212
let len = req.len();
1313
response.set_body(Body::from_reader(req, len));
14-
Ok(response)
14+
response
1515
});
1616

1717
let content_length = 10;
@@ -35,7 +35,7 @@ mod accept {
3535

3636
#[async_std::test]
3737
async fn request_close() -> Result<()> {
38-
let mut server = TestServer::new(|_| async { Ok(Response::new(200)) });
38+
let mut server = TestServer::new(|_| async { Response::new(200) });
3939

4040
server
4141
.write_all(b"GET / HTTP/1.1\r\nHost: example.com\r\nConnection: Close\r\n\r\n")
@@ -53,7 +53,7 @@ mod accept {
5353
let mut server = TestServer::new(|_| async {
5454
let mut response = Response::new(200);
5555
response.insert_header(CONNECTION, "close");
56-
Ok(response)
56+
response
5757
});
5858

5959
server
@@ -69,7 +69,7 @@ mod accept {
6969

7070
#[async_std::test]
7171
async fn keep_alive_short_fixed_length_unread_body() -> Result<()> {
72-
let mut server = TestServer::new(|_| async { Ok(Response::new(200)) });
72+
let mut server = TestServer::new(|_| async { Response::new(200) });
7373

7474
let content_length = 10;
7575

@@ -95,7 +95,7 @@ mod accept {
9595

9696
#[async_std::test]
9797
async fn keep_alive_short_chunked_unread_body() -> Result<()> {
98-
let mut server = TestServer::new(|_| async { Ok(Response::new(200)) });
98+
let mut server = TestServer::new(|_| async { Response::new(200) });
9999

100100
let content_length = 100;
101101

@@ -125,7 +125,7 @@ mod accept {
125125

126126
#[async_std::test]
127127
async fn keep_alive_long_fixed_length_unread_body() -> Result<()> {
128-
let mut server = TestServer::new(|_| async { Ok(Response::new(200)) });
128+
let mut server = TestServer::new(|_| async { Response::new(200) });
129129

130130
let content_length = 10000;
131131

@@ -151,7 +151,7 @@ mod accept {
151151

152152
#[async_std::test]
153153
async fn keep_alive_long_chunked_unread_body() -> Result<()> {
154-
let mut server = TestServer::new(|_| async { Ok(Response::new(200)) });
154+
let mut server = TestServer::new(|_| async { Response::new(200) });
155155

156156
let content_length = 10000;
157157

tests/test_utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use async_h1::{
33
server::{ConnectionStatus, Server},
44
};
55
use async_std::io::{Read, Write};
6-
use http_types::{Request, Response, Result};
6+
use http_types::{Request, Response};
77
use std::{
88
fmt::{Debug, Display},
99
future::Future,
@@ -25,7 +25,7 @@ pub struct TestServer<F, Fut> {
2525
impl<F, Fut> TestServer<F, Fut>
2626
where
2727
F: Fn(Request) -> Fut,
28-
Fut: Future<Output = Result<Response>>,
28+
Fut: Future<Output = Response>,
2929
{
3030
#[allow(dead_code)]
3131
pub fn new(f: F) -> Self {
@@ -61,7 +61,7 @@ where
6161
impl<F, Fut> Read for TestServer<F, Fut>
6262
where
6363
F: Fn(Request) -> Fut,
64-
Fut: Future<Output = Result<Response>>,
64+
Fut: Future<Output = Response>,
6565
{
6666
fn poll_read(
6767
self: Pin<&mut Self>,
@@ -75,7 +75,7 @@ where
7575
impl<F, Fut> Write for TestServer<F, Fut>
7676
where
7777
F: Fn(Request) -> Fut,
78-
Fut: Future<Output = Result<Response>>,
78+
Fut: Future<Output = Response>,
7979
{
8080
fn poll_write(
8181
self: Pin<&mut Self>,

0 commit comments

Comments
 (0)