Skip to content

Commit

Permalink
Merge pull request #39 from ideal-world/tcp-gate
Browse files Browse the repository at this point in the history
fix build error, fix cicd error
  • Loading branch information
4t145 authored Oct 21, 2024
2 parents e4df383 + dd64ae0 commit 0d275c5
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 458 deletions.
10 changes: 7 additions & 3 deletions crates/kernel/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,16 @@ impl TcpService for Https {
}
}

#[derive(Clone)]
pub(crate) struct HyperServiceAdapter<S>
#[derive(Clone, Debug)]
pub struct HyperServiceAdapter<S>
where
S: hyper::service::Service<Request<SgBody>, Error = Infallible, Response = Response<SgBody>> + Clone + Send + 'static,
S::Future: Send + 'static,
{
service: S,
peer: SocketAddr,
}

impl<S> HyperServiceAdapter<S>
where
S: hyper::service::Service<Request<SgBody>, Error = Infallible, Response = Response<SgBody>> + Clone + Send + 'static,
Expand Down Expand Up @@ -148,14 +149,17 @@ where
let service = self.service.clone();
let mut req = req.map(SgBody::new);
let mut reflect = Reflect::default();
let method = req.method().clone();
reflect.insert(enter_time);
req.extensions_mut().insert(reflect);
req.extensions_mut().insert(PeerAddr(self.peer));
req.extensions_mut().insert(enter_time);

Box::pin(async move {
let mut resp = service.call(req).await.expect("infallible");
with_length_or_chunked(&mut resp);
if method != hyper::Method::CONNECT {
with_length_or_chunked(&mut resp);
}
let status = resp.status();
if status.is_server_error() {
tracing::warn!(status = ?status, headers = ?resp.headers(), "server error response");
Expand Down
4 changes: 2 additions & 2 deletions crates/model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ impl Default for Config {
Self {
gateways: Default::default(),
plugins: Default::default(),
#[cfg(feature = "axum")]
#[cfg(feature = "ext-axum")]
api_port: Some(crate::constants::DEFAULT_API_PORT),
#[cfg(not(feature = "axum"))]
#[cfg(not(feature = "ext-axum"))]
api_port: None,
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/plugin/src/ext/redis/plugins.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use hyper::{header::HeaderName, Request};
use serde::{Deserialize, Serialize};
use spacegate_kernel::{extension::MatchedSgRouter, service::http_route::match_request::HttpPathMatchRewrite, SgBody};

pub mod redis_count;
Expand All @@ -24,7 +23,7 @@ fn redis_format_key(req: &Request<SgBody>, matched: &MatchedSgRouter, header: &H
}

#[cfg(feature = "axum")]
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, serde::Serialize, serde::Deserialize)]
pub struct MatchSpecifier {
/// None for Any
pub method: Option<String>,
Expand Down
3 changes: 1 addition & 2 deletions crates/shell/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use std::collections::VecDeque;
use std::net::SocketAddr;

use crate::server::RunningSgGateway;
use futures_util::{Stream, StreamExt};
Expand Down Expand Up @@ -45,7 +44,7 @@ where
spacegate_plugin::ext::axum::register_plugin_routes().await;
server.set_cancellation(shutdown_signal.child_token()).await;
if let Some(port) = init_config.api_port {
server.set_bind(SocketAddr::new(std::net::IpAddr::V4(std::net::Ipv4Addr::UNSPECIFIED), port)).await;
server.set_bind(std::net::SocketAddr::new(std::net::IpAddr::V4(std::net::Ipv4Addr::UNSPECIFIED), port)).await;
}
server.start().await?;
info!("Web server started.");
Expand Down
Loading

0 comments on commit 0d275c5

Please sign in to comment.