Skip to content

Commit beed268

Browse files
authored
Merge pull request apache#38 from wangtuanjie/wtj2
lsproxy support fwd proxy
2 parents 9f7a37a + b2e3424 commit beed268

File tree

2 files changed

+38
-12
lines changed

2 files changed

+38
-12
lines changed
Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,24 @@
1-
LOCAL STATD PROXY
1+
LOCAL SECURITY PROXY
22
-----------------
33

4-
本地的正向STATD代理服务器,主要功能增加了鉴权,方便本地浏览statd的数据
4+
本地的正向HTTP代理服务器,方便本地调用鉴权的接口
55

6-
使用方法
7-
* `./pili-lsproxy -access "<admin access key>" -secret "<admin secret key>"`
8-
* 然后本地浏览器打开`http://127.0.0.1:8090/statd/chart/upflow?$uid=1380603831&start=20160601&g=day&select=flow`
6+
## 运行方法
7+
`./pili-lsproxy -access "<access key>" -secret "<secret key>" [-host "<default host>"`]
8+
9+
10+
## 使用方法
11+
12+
#### 直接请求
13+
`curl -vv 'http://127.0.0.1:8090/v2/hubs/inlive/monitor/publish?$uid=1380301031'`
14+
15+
此时目标为运行参数指定的host
16+
17+
#### 正向代理
18+
`curl -vv 'http://pili.qiniuapi.com/v2/hubs/inlive/monitor/publish?$uid=1380301031' -x 127.0.0.1:8090`
19+
20+
21+
## 权限
22+
* 当前只支持`qiniu/mac`形式的鉴权
23+
* sudo,尝试从`url.Query`提取`$uid`参数,需要admin权限
24+
* 没指定`$uid`参数时,使用参数指定的密钥直接签名

go/src/pili.qiniu.com/app/pili-lsproxy/main.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ import (
1414
func main() {
1515

1616
var (
17-
host = flag.String("host", "pili.qiniuapi.com", "dest host")
18-
accessKey = flag.String("access", "", "access key")
19-
secretKey = flag.String("secret", "", "secret key")
20-
addr = flag.String("addr", ":8090", "run addr")
17+
defaultHost = flag.String("host", "pili.qiniuapi.com", "default host")
18+
accessKey = flag.String("access", "", "access key")
19+
secretKey = flag.String("secret", "", "secret key")
20+
addr = flag.String("addr", ":8090", "run addr")
21+
https = flag.Bool("https", true, "use https scheme")
2122
)
2223
flag.Parse()
2324

@@ -26,9 +27,18 @@ func main() {
2627
SecretKey: []byte(*secretKey),
2728
}
2829

30+
scheme := "http"
31+
if *https {
32+
scheme = "https"
33+
}
34+
2935
http.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
3036

3137
var tr http.RoundTripper
38+
host := req.URL.Host
39+
if host == "" {
40+
host = *defaultHost
41+
}
3242

3343
query := req.URL.Query()
3444
uid := query.Get("$uid")
@@ -41,10 +51,10 @@ func main() {
4151
}
4252

4353
u := &url.URL{
44-
Scheme: "http",
45-
Host: *host,
54+
Scheme: scheme,
55+
Host: host,
4656
}
47-
req.Host = *host
57+
req.Host = host
4858

4959
proxy := httputil.NewSingleHostReverseProxy(u)
5060
proxy.Transport = tr

0 commit comments

Comments
 (0)