Skip to content

Commit 2d07be4

Browse files
committed
Lift connect & accept to top-level
1 parent ca516c5 commit 2d07be4

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

examples/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ async fn main() -> http_types::Result<()> {
2727
// Take a TCP stream, and convert it into sequential HTTP request / response pairs.
2828
async fn accept(addr: String, stream: TcpStream) -> http_types::Result<()> {
2929
println!("starting new connection from {}", stream.peer_addr()?);
30-
async_h1::server::accept(&addr, stream.clone(), |_req| async move {
30+
async_h1::accept(&addr, stream.clone(), |_req| async move {
3131
let mut res = Response::new(StatusCode::Ok);
3232
res.insert_header("Content-Type", "text/plain")?;
3333
res.set_body("Hello");

src/client.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use crate::date::fmt_http_date;
1818
use crate::MAX_HEADERS;
1919

2020
/// An HTTP encoder.
21+
#[doc(hidden)]
2122
#[derive(Debug)]
2223
pub struct Encoder {
2324
/// Keep track how far we've indexed into the headers + body.
@@ -65,7 +66,8 @@ where
6566
}
6667

6768
/// Encode an HTTP request on the client.
68-
pub async fn encode(req: Request) -> Result<Encoder, Error> {
69+
#[doc(hidden)]
70+
async fn encode(req: Request) -> Result<Encoder, Error> {
6971
let mut buf: Vec<u8> = vec![];
7072

7173
let mut url = req.url().path().to_owned();
@@ -132,6 +134,7 @@ pub async fn encode(req: Request) -> Result<Encoder, Error> {
132134
}
133135

134136
/// Decode an HTTP response on the client.
137+
#[doc(hidden)]
135138
pub async fn decode<R>(reader: R) -> Result<Response, Error>
136139
where
137140
R: Read + Unpin + Send + Sync + 'static,

src/lib.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,12 @@
3636
/// The maximum amount of headers parsed on the server.
3737
const MAX_HEADERS: usize = 128;
3838

39+
mod server;
40+
mod chunked;
41+
mod date;
3942

43+
#[doc(hidden)]
4044
pub mod client;
41-
pub mod server;
4245

43-
mod chunked;
44-
mod date;
46+
pub use client::connect;
47+
pub use server::accept;

tests/server.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use async_h1::server;
21
use async_std::io::Cursor;
32
use async_std::prelude::*;
43
use common::TestCase;
@@ -11,7 +10,7 @@ async fn test_basic_request() {
1110
let case = TestCase::new_server("fixtures/request1.txt", "fixtures/response1.txt").await;
1211
let addr = "http://example.com";
1312

14-
server::accept(addr, case.clone(), |_req| async {
13+
async_h1::accept(addr, case.clone(), |_req| async {
1514
let mut resp = Response::new(StatusCode::Ok);
1615
resp.set_body("");
1716
Ok(resp)
@@ -31,7 +30,7 @@ async fn test_chunked_basic() {
3130
.await;
3231
let addr = "http://example.com";
3332

34-
server::accept(addr, case.clone(), |_req| async {
33+
async_h1::accept(addr, case.clone(), |_req| async {
3534
let mut resp = Response::new(StatusCode::Ok);
3635
resp.set_body(Body::from_reader(
3736
Cursor::new(b"Mozilla")
@@ -57,7 +56,7 @@ async fn test_chunked_echo() {
5756
.await;
5857
let addr = "http://example.com";
5958

60-
server::accept(addr, case.clone(), |req| async {
59+
async_h1::accept(addr, case.clone(), |req| async {
6160
let mut resp = Response::new(StatusCode::Ok);
6261
let ct = req.content_type();
6362
let body: Body = req.into();

0 commit comments

Comments
 (0)