Skip to content

Commit 662be70

Browse files
committed
Debugging first version of mcp path
1 parent 0a65ebe commit 662be70

File tree

13 files changed

+231
-91
lines changed

13 files changed

+231
-91
lines changed

src/configurations/my_reverse_proxy_remote_endpoint.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ impl MyReverseProxyRemoteEndpoint {
3535
MyReverseProxyRemoteEndpoint::Direct { remote_host } => Some(remote_host.get_host()),
3636
}
3737
}
38+
39+
pub fn get_path_and_query(&self) -> &str {
40+
match self {
41+
MyReverseProxyRemoteEndpoint::Gateway { id: _, remote_host } => {
42+
remote_host.get_http_path_and_query().unwrap_or("/")
43+
}
44+
MyReverseProxyRemoteEndpoint::OverSsh {
45+
ssh_credentials: _,
46+
remote_host,
47+
} => remote_host.get_http_path_and_query().unwrap_or("/"),
48+
MyReverseProxyRemoteEndpoint::Direct { remote_host } => {
49+
remote_host.get_http_path_and_query().unwrap_or("/")
50+
}
51+
}
52+
}
3853
pub async fn try_parse(
3954
remote_host: &str,
4055
settings_model: &SettingsCompiled,

src/configurations/proxy_pass_location_config.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ impl ProxyPassLocationConfig {
146146
}
147147
}
148148
},
149+
149150
ProxyPassToConfig::Http2(proxy_pass) => match &proxy_pass.remote_host {
150151
MyReverseProxyRemoteEndpoint::Gateway { .. } => {
151152
todo!("Should not be here. Remote it at the end of the day");

src/configurations/proxy_pass_to_config.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ pub struct ProxyPassToModel {
3636
pub remote_host: MyReverseProxyRemoteEndpoint,
3737
pub request_timeout: Duration,
3838
pub connect_timeout: Duration,
39+
pub is_mcp: bool,
3940
}
4041

4142
#[derive(Debug)]
@@ -55,19 +56,20 @@ impl ProxyPassToConfig {
5556
ProxyPassToConfig::UnixHttp1(proxy_pass) => proxy_pass.remote_host.to_string(),
5657
ProxyPassToConfig::UnixHttp2(proxy_pass) => proxy_pass.remote_host.to_string(),
5758
ProxyPassToConfig::Http2(proxy_pass) => proxy_pass.remote_host.to_string(),
59+
5860
ProxyPassToConfig::FilesPath(model) => model.to_string(),
5961
ProxyPassToConfig::Static(model) => model.to_string(),
6062
}
6163
}
6264

6365
pub fn get_type_as_str(&self) -> &'static str {
6466
match self {
65-
ProxyPassToConfig::UnixHttp1(_) => "unix+http1",
66-
ProxyPassToConfig::UnixHttp2(_) => "unix+http2",
67-
ProxyPassToConfig::Http1(_) => "http1",
68-
ProxyPassToConfig::Http2(_) => "http2",
69-
ProxyPassToConfig::FilesPath(_) => "files_path",
70-
ProxyPassToConfig::Static(_) => "static",
67+
Self::UnixHttp1(_) => "unix+http1",
68+
Self::UnixHttp2(_) => "unix+http2",
69+
Self::Http1(_) => "http1",
70+
Self::Http2(_) => "http2",
71+
Self::FilesPath(_) => "files_path",
72+
Self::Static(_) => crate::consts::location_type::STATIC,
7173
}
7274
}
7375
}

src/consts.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,9 @@ pub const WRITE_TIMEOUT: Duration = Duration::from_secs(30);
1010
pub const HTTP_CR_LF: &[u8] = b"\r\n";
1111

1212
pub const AUTHORIZED_COOKIE_NAME: &str = "x-authorized";
13+
14+
pub mod location_type {
15+
16+
pub const MCP: &'static str = "mcp";
17+
pub const STATIC: &'static str = "static";
18+
}

src/error_templates/generate_layout.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ pub fn generate_layout(status_code: u16, text: &str, second_line: Option<StrOrSt
5555
.into_bytes();
5656

5757
let mut headers = crate::h1_utils::Http1HeadersBuilder::new();
58-
headers.add_response_first_line(200);
58+
headers.push_response_first_line(200);
5959

60-
headers.add_content_length(body.len());
61-
headers.write_cl_cr();
60+
headers.push_content_length(body.len());
61+
headers.push_cl_cr();
6262

6363
let mut result = headers.into_bytes();
6464
result.extend_from_slice(body.as_bytes());

src/h1_proxy_server/h1_read_part.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,24 @@ impl<TNetworkReadPart: NetworkStreamReadPart + Send + Sync + 'static> H1Reader<T
108108
modify_headers: &ModifyHeadersConfig,
109109
http_connection_info: &HttpConnectionInfo,
110110
identity: &Option<HttpProxyPassIdentity>,
111+
mcp_path: Option<&str>,
111112
) -> Result<bool, ProxyServerError> {
112113
self.h1_headers_builder.clear();
113114
let data = self.loop_buffer.get_data();
114115

115-
self.h1_headers_builder.push_raw_payload(
116-
&data[..http_headers.first_line_end + crate::consts::HTTP_CR_LF.len()],
117-
);
116+
if let Some(mcp_path) = mcp_path {
117+
println!("Pushing mcp path {}", mcp_path);
118+
http_headers.push_first_line_with_other_path(
119+
data,
120+
mcp_path,
121+
&mut self.h1_headers_builder,
122+
);
123+
self.h1_headers_builder.push_cl_cr();
124+
} else {
125+
self.h1_headers_builder.push_raw_payload(
126+
&data[..http_headers.first_line_end + crate::consts::HTTP_CR_LF.len()],
127+
);
128+
}
118129

119130
let mut pos = http_headers.first_line_end + crate::consts::HTTP_CR_LF.len();
120131

@@ -161,9 +172,9 @@ impl<TNetworkReadPart: NetworkStreamReadPart + Send + Sync + 'static> H1Reader<T
161172
add_header.1.as_str(),
162173
);
163174
self.h1_headers_builder
164-
.add_header(add_header.0, value.as_str());
175+
.push_header(add_header.0, value.as_str());
165176
}
166-
self.h1_headers_builder.write_cl_cr();
177+
self.h1_headers_builder.push_cl_cr();
167178

168179
let mut web_socket_upgrade = false;
169180

src/h1_proxy_server/server_loop.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ async fn execute_request<
179179
&end_point_info.modify_request_headers,
180180
&http_connection_info,
181181
&identity,
182+
connection.mcp_path.as_deref(),
182183
)?;
183184

184185
let send_headers_result = connection

0 commit comments

Comments
 (0)