Skip to content

Commit 3b84f62

Browse files
committed
Do http request and response
1 parent c593a31 commit 3b84f62

File tree

4 files changed

+12
-0
lines changed

4 files changed

+12
-0
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ edition = "2021"
66
[dependencies]
77
clap = "4.5.4"
88
futures = "0.3.30"
9+
httparse = "1.8.0"
910
litep2p = "0.5.0"
1011
# Do not upgrade multiaddr, see: https://github.com/paritytech/litep2p/pull/91
1112
multiaddr = "0.17.1"

src/error.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ pub enum Error {
1212
Litep2p(#[from] litep2p::Error),
1313
#[error("Litep2p request response error: {0:?}")]
1414
Litep2pRequestResponseError(litep2p::protocol::request_response::RequestResponseError),
15+
#[error("Httparse error: {0}")]
16+
Httparse(#[from] httparse::Error),
17+
#[error("Incomplete http request")]
18+
IncompleteHttpRequest,
1519
#[error("Unexpected response type")]
1620
UnexpectedResponseType,
1721
}

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ impl PProxyHandle {
212212
&self,
213213
request: RequestHttpServerRequest,
214214
) -> Result<RequestHttpServerResponse> {
215+
let mut headers = [httparse::EMPTY_HEADER; 64];
216+
let mut req = httparse::Request::new(&mut headers);
217+
if req.parse(&request.data)?.is_partial() {
218+
return Err(Error::IncompleteHttpRequest);
219+
}
220+
215221
let (tx, rx) = oneshot::channel();
216222

217223
self.command_tx

0 commit comments

Comments
 (0)