Skip to content

Commit 99fff62

Browse files
committed
Compatible with protoc that not enable proto3
1 parent c593a31 commit 99fff62

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
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"

build.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
fn main() -> Result<(), Box<dyn std::error::Error>> {
2-
tonic_build::compile_protos("proto/command_v1.proto")?;
2+
tonic_build::configure()
3+
.protoc_arg("--experimental_allow_proto3_optional")
4+
.compile(&["proto/command_v1.proto"], &["proto"])?;
35
Ok(())
46
}

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)