Skip to content

Commit

Permalink
Add HTTP client for network module (#1100)
Browse files Browse the repository at this point in the history
  • Loading branch information
twitu authored May 12, 2023
1 parent f210d4c commit 57b61e8
Show file tree
Hide file tree
Showing 7 changed files with 413 additions and 1 deletion.
187 changes: 187 additions & 0 deletions nautilus_core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion nautilus_core/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ nautilus_core = { path = "../core" }
pyo3.workspace = true
pyo3-asyncio.workspace = true
tokio.workspace = true
hyper = "0.14.26"
hyper = { version = "0.14.26", features = ["client", "http2"] }
hyper-tls = "0.5.0"

[features]
extension-module = ["pyo3/extension-module", "nautilus_core/extension-module"]
Expand Down
43 changes: 43 additions & 0 deletions nautilus_core/network/benches/bench_client.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// -------------------------------------------------------------------------------------------------
// Copyright (C) 2015-2023 Nautech Systems Pty Ltd. All rights reserved.
// https://nautechsystems.io
//
// Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
// You may not use this file except in compliance with the License.
// You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// -------------------------------------------------------------------------------------------------
//
use std::collections::HashMap;

use hyper::Method;
use nautilus_network::HttpClient;

// Testing with nginx docker container
// `docker run --publish 8080:80 nginx`
#[tokio::main]
async fn main() {
let client = HttpClient::default();
let mut success = 0;
for _ in 0..100_000 {
if let Ok(resp) = client
.send_request(
Method::GET,
"http://localhost:8080".to_string(),
HashMap::new(),
)
.await
{
if resp.status == 200 {
success += 1;
}
}
}

println!("Successful requests: {}", success);
}
Loading

0 comments on commit 57b61e8

Please sign in to comment.