Skip to content

Commit

Permalink
g3proxy: use less param in http proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
zh-jq-b committed Dec 5, 2024
1 parent e165c18 commit 6d0cbcf
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
6 changes: 3 additions & 3 deletions g3proxy/src/log/task/http_forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl TaskLogForHttpForward<'_> {
"tcp_connect_tries" => self.tcp_notes.tries,
"tcp_connect_spend" => LtDuration(self.tcp_notes.duration),
"pipeline_wait" => LtDuration(self.http_notes.pipeline_wait),
"reuse_connection" => self.http_notes.reuse_connection,
"reuse_connection" => self.http_notes.reused_connection,
"method" => LtHttpMethod(&self.http_notes.method),
"uri" => LtHttpUri::new(&self.http_notes.uri, self.http_notes.uri_log_max_chars),
"user_agent" => self.http_user_agent,
Expand Down Expand Up @@ -123,7 +123,7 @@ impl TaskLogForHttpForward<'_> {
"tcp_connect_tries" => self.tcp_notes.tries,
"tcp_connect_spend" => LtDuration(self.tcp_notes.duration),
"pipeline_wait" => LtDuration(self.http_notes.pipeline_wait),
"reuse_connection" => self.http_notes.reuse_connection,
"reuse_connection" => self.http_notes.reused_connection,
"method" => LtHttpMethod(&self.http_notes.method),
"uri" => LtHttpUri::new(&self.http_notes.uri, self.http_notes.uri_log_max_chars),
"user_agent" => self.http_user_agent,
Expand Down Expand Up @@ -169,7 +169,7 @@ impl TaskLogForHttpForward<'_> {
"tcp_connect_spend" => LtDuration(self.tcp_notes.duration),
"reason" => e.brief(),
"pipeline_wait" => LtDuration(self.http_notes.pipeline_wait),
"reuse_connection" => self.http_notes.reuse_connection,
"reuse_connection" => self.http_notes.reused_connection,
"method" => LtHttpMethod(&self.http_notes.method),
"uri" => LtHttpUri::new(&self.http_notes.uri, self.http_notes.uri_log_max_chars),
"user_agent" => self.http_user_agent,
Expand Down
4 changes: 2 additions & 2 deletions g3proxy/src/module/http_forward/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub(crate) struct HttpForwardTaskNotes {
pub(crate) rsp_status: u16,
pub(crate) origin_status: u16,
pub(crate) pipeline_wait: Duration,
pub(crate) reuse_connection: bool,
pub(crate) reused_connection: bool,
create_ins: Instant,
pub(crate) dur_req_send_hdr: Duration,
pub(crate) dur_req_send_all: Duration,
Expand All @@ -48,7 +48,7 @@ impl HttpForwardTaskNotes {
rsp_status: 0,
origin_status: 0,
pipeline_wait: req_received.elapsed(),
reuse_connection: false,
reused_connection: false,
create_ins: task_created,
dur_req_send_hdr: Duration::default(),
dur_req_send_all: Duration::default(),
Expand Down
11 changes: 5 additions & 6 deletions g3proxy/src/serve/http_proxy/task/forward/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,15 +612,15 @@ impl<'a> HttpProxyForwardTask<'a> {
.await
{
self.task_notes.stage = ServerTaskStage::Connected;
self.http_notes.reuse_connection = true;
self.http_notes.reused_connection = true;
fwd_ctx.fetch_tcp_notes(&mut self.tcp_notes);
self.http_notes.retry_new_connection = true;
if let Some(user_ctx) = self.task_notes.user_ctx() {
user_ctx.foreach_req_stats(|s| s.req_reuse.add_http_forward(self.is_https));
}

let r = self
.run_with_connection(clt_r, clt_w, connection, true, audit_task)
.run_with_connection(clt_r, clt_w, connection, audit_task)
.await;
match r {
Ok(r) => {
Expand Down Expand Up @@ -648,14 +648,14 @@ impl<'a> HttpProxyForwardTask<'a> {
}

self.task_notes.stage = ServerTaskStage::Connecting;
self.http_notes.reuse_connection = false;
self.http_notes.reused_connection = false;
match self.make_new_connection(fwd_ctx).await {
Ok(connection) => {
self.task_notes.stage = ServerTaskStage::Connected;
fwd_ctx.fetch_tcp_notes(&mut self.tcp_notes);

let r = self
.run_with_connection(clt_r, clt_w, connection, false, audit_task)
.run_with_connection(clt_r, clt_w, connection, audit_task)
.await;
// handle result
match r {
Expand Down Expand Up @@ -729,14 +729,13 @@ impl<'a> HttpProxyForwardTask<'a> {
clt_r: &'f mut Option<HttpClientReader<CDR>>,
clt_w: &'f mut HttpClientWriter<CDW>,
mut ups_c: BoxHttpForwardConnection,
reused_connection: bool,
audit_task: bool,
) -> ServerTaskResult<Option<BoxHttpForwardConnection>>
where
CDR: AsyncRead + Send + Unpin,
CDW: AsyncWrite + Send + Unpin,
{
if reused_connection {
if self.http_notes.reused_connection {
if let Some(r) = ups_c.1.fill_wait_eof().now_or_never() {
return match r {
Ok(_) => Err(ServerTaskError::ClosedByUpstream),
Expand Down
15 changes: 5 additions & 10 deletions g3proxy/src/serve/http_rproxy/task/forward/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,16 +505,14 @@ impl<'a> HttpRProxyForwardTask<'a> {
.await
{
self.task_notes.stage = ServerTaskStage::Connected;
self.http_notes.reuse_connection = true;
self.http_notes.reused_connection = true;
fwd_ctx.fetch_tcp_notes(&mut self.tcp_notes);
self.retry_new_connection = true;
if let Some(user_ctx) = self.task_notes.user_ctx() {
user_ctx.foreach_req_stats(|s| s.req_reuse.add_http_forward(self.is_https));
}

let r = self
.run_with_connection(clt_r, clt_w, connection, true)
.await;
let r = self.run_with_connection(clt_r, clt_w, connection).await;
match r {
Ok(r) => {
if let Some(connection) = r {
Expand All @@ -541,15 +539,13 @@ impl<'a> HttpRProxyForwardTask<'a> {
}

self.task_notes.stage = ServerTaskStage::Connecting;
self.http_notes.reuse_connection = false;
self.http_notes.reused_connection = false;
match self.make_new_connection(fwd_ctx).await {
Ok(connection) => {
self.task_notes.stage = ServerTaskStage::Connected;
fwd_ctx.fetch_tcp_notes(&mut self.tcp_notes);

let r = self
.run_with_connection(clt_r, clt_w, connection, false)
.await;
let r = self.run_with_connection(clt_r, clt_w, connection).await;
// handle result
match r {
Ok(r) => {
Expand Down Expand Up @@ -613,13 +609,12 @@ impl<'a> HttpRProxyForwardTask<'a> {
clt_r: &'f mut Option<HttpClientReader<CDR>>,
clt_w: &'f mut HttpClientWriter<CDW>,
mut ups_c: BoxHttpForwardConnection,
reused_connection: bool,
) -> ServerTaskResult<Option<BoxHttpForwardConnection>>
where
CDR: AsyncRead + Unpin,
CDW: AsyncWrite + Unpin,
{
if reused_connection {
if self.http_notes.reused_connection {
if let Some(r) = ups_c.1.fill_wait_eof().now_or_never() {
return match r {
Ok(_) => Err(ServerTaskError::ClosedByUpstream),
Expand Down

0 comments on commit 6d0cbcf

Please sign in to comment.