Skip to content

Commit 4861111

Browse files
committed
doc: update readme
- 更新README - 优化代码
1 parent e5b3d06 commit 4861111

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
- 解析 JWT 凭证:如果 `header` 中包含字段 `Authorization`,且符合 [`Bearer <token>`](https://swagger.io/docs/specification/authentication/bearer-authentication/) 格式 ,则会对其进行 JWT 解码,然后传递给业务逻辑层。
1010

11+
- 根据特定的Cookie记录重定向。解决 [SwanHubX/habitat#121](https://github.com/SwanHubX/habitat/issues/121)
12+
1113
上述功能都不会干预响应,而是将解析的身份信息放置在请求头 `payload` 上,然后逻辑层根据请求头是否含有 `payload` 参数来判断请求是否携带有效凭证。
1214

1315
### 使用
@@ -79,3 +81,4 @@ http:
7981
8082
- `AuthUrl`(可选):转发的认证接口
8183
- `Key`(可选):RSA公钥
84+
- `Mark`(可选):特定的标识。例如Mark设置为 `ht-`,Cookie中有一个Key为 `ht-iop`,那么重定向时将添加路径前缀 `/iop`

preprocess.go

+11-4
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,17 @@ func (p *Preprocess) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
6666
if p.mark != "" && p.redirect(req, rw) {
6767
return
6868
}
69-
// 删除可能的payload头
70-
req.Header.Del("payload")
71-
p.forwardAuth(req) // 对会话进行转发验证
72-
p.parseJWT(req) // 对携带JWT凭证的请求进行解析
69+
if p.url != "" || p.publicKey != nil {
70+
// 删除可能存在的payload头
71+
req.Header.Del("payload")
72+
}
73+
if p.url != "" {
74+
// 对会话进行转发认证
75+
p.forwardAuth(req)
76+
} else if p.publicKey != nil {
77+
// 对携带JWT凭证的请求进行解析
78+
p.parseJWT(req)
79+
}
7380
p.addTraceId(req, rw) // 对请求添加traceId
7481
p.next.ServeHTTP(rw, req)
7582
}

0 commit comments

Comments
 (0)