Skip to content

Commit

Permalink
docs: update document
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Apr 14, 2024
1 parent 143dfca commit c5f9eb3
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ A reverse proxy like nginx, built on [pingora](https://github.com/cloudflare/pin
- Graceful reload
- Template for http access log
- TOML base configuration
- Admin Web UI configuration

## Start

Expand Down
7 changes: 5 additions & 2 deletions docs/introduction_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,25 @@ Pingap是基于[pingora](https://github.com/cloudflare/pingora)开发的,pingo
- 支持HTTP1与HTTP2两种协议
- 无中断请求的配置更新,方便实时更新应用配置
- 模板式的请求日志输出,可按模板指定各种输出
- 提供Web界面式的配置,简化操作

[Pingap处理流程](./phase_chart_zh.md)

## 根据请求的路径选择对应的服务
## 请求筛选

Pingap支持两种特别的服务类型,以及常规的反向代理服务,具体如下:
Pingap支持以下的服务类型,以及常规的反向代理服务,具体如下:

- `Stats`: 获取Server所对应的性能指标
- `Admin`: 根据启动时指定的admin地址或者配置的`admin path`转发至对应的管理后台服务
- `Directory`: 根据指定的静态目录提供静态文件服务
- `其它`: 常规的反向代理服务,根据域名与路径选择对应的转发节点

```mermaid
graph TD;
start("新的请求")-->ServiceFilter{{请求服务筛选}};
ServiceFilter--是否匹配stats-->stats的处理;
ServiceFilter--是否匹配admin-->admin的处理;
ServiceFilter--是否匹配静态文件目录-->静态文件的处理;
ServiceFilter--根据host与path选择对应的Location-->Location筛选处理;
```

Expand Down
4 changes: 2 additions & 2 deletions docs/phase_chart_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ description: Pingap 处理流程

```mermaid
flowchart TB
start("新的请求")-->requestFilter{{请求过滤}};
subgraph 针对请求过滤流程
start("新的请求")-->requestFilter{{请求筛选}};
subgraph 针对请求筛选流程
requestFilter--匹配stats路径-->stats处理
requestFilter--匹配admin-->admin处理
requestFilter--常规upstream转发-->location处理
Expand Down
5 changes: 5 additions & 0 deletions docs/request_filter_zh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
description: 请求筛选
---

Pingora的HttpProxy流程中,若需要对
27 changes: 19 additions & 8 deletions src/proxy/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -443,27 +443,38 @@ impl ProxyHttp for Server {
}

ctx.location_index = Some(location_index);

// TODO get response from cache
// check location support cache

Ok(false)
}
async fn proxy_upstream_filter(
&self,
session: &mut Session,
ctx: &mut Self::CTX,
) -> pingora::Result<bool>
where
Self::CTX: Send + Sync,
{
let lo = &self.locations[ctx.location_index.unwrap_or_default()];
if let Some(dir) = lo.upstream.as_directory() {
let result = dir.handle(session, ctx).await?;
return Ok(result);
return Ok(!result);
}
if let Some(mock) = lo.upstream.as_mock() {
let result = mock.handle(session, ctx).await?;
return Ok(result);
return Ok(!result);
}
// TODO get response from cache
// check location support cache

Ok(false)
Ok(true)
}

async fn upstream_peer(
&self,
session: &mut Session,
ctx: &mut State,
) -> pingora::Result<Box<HttpPeer>> {
let lo = &self.locations[ctx.location_index.unwrap_or_default()];

// pingora::Error::new_str("No available upstream")
let peer = lo.upstream.new_http_peer(ctx, session).ok_or_else(|| {
util::new_internal_error(503, format!("No available upstream({})", lo.upstream_name))
})?;
Expand Down

0 comments on commit c5f9eb3

Please sign in to comment.