Skip to content

Commit

Permalink
feat: support specify path and query for web proxy
Browse files Browse the repository at this point in the history
Signed-off-by: Jianhui Zhao <[email protected]>
  • Loading branch information
zhaojh329 committed May 9, 2022
1 parent f8efeaf commit ed85912
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
14 changes: 12 additions & 2 deletions http.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,20 @@ func httpProxyRedirect(br *broker, c *gin.Context) {
cfg := br.cfg
devid := c.Param("devid")
addr := c.Param("addr")
path := c.Param("path")
rawPath := c.Param("path")

_, _, err := httpProxyVaildAddr(addr)
if err != nil {
c.Status(http.StatusBadRequest)
return
}

path, err := url.Parse(rawPath)
if err != nil {
c.Status(http.StatusBadRequest)
return
}

_, ok := br.devices[devid]
if !ok {
c.Status(http.StatusNotFound)
Expand All @@ -266,10 +272,14 @@ func httpProxyRedirect(br *broker, c *gin.Context) {
}
}

location += path
location += path.Path

location += fmt.Sprintf("?_=%d", time.Now().Unix())

if path.RawQuery != "" {
location += "&" + path.RawQuery
}

sid, err := c.Cookie("rtty-http-sid")
if err == nil {
if v, ok := httpProxySessions.Load(sid); ok {
Expand Down
25 changes: 17 additions & 8 deletions ui/src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -360,28 +360,37 @@ export default {
}
}
});
return h('div', [input, h('p', '127.0.0.1, 127.0.0.1:8080, http://127.0.0.1')]);
return h('div', [input, h('p', '127.0.0.1, 127.0.0.1:8080, 127.0.0.1/test.html?a=1')]);
},
onOk: () => {
const addrs = addr.split(':');
let [addrs, ...path] = addr.split('/');
if (!this.parseIPv4(addrs[0])) {
path = '/' + path.join('/');
let [ip, ...port] = addrs.split(':');
if (!this.parseIPv4(ip)) {
this.$Message.error(this.$t('Invalid address'));
return;
}
let port = 80;
if (port.length !== 0 && port.length !== 1) {
this.$Message.error(this.$t('Invalid port'));
return;
}
if (addrs.length > 0) {
port = Number(addrs[1]);
if (port.length === 1) {
port = Number(port[0]);
if (port <= 0 || port > 65535) {
this.$Message.error(this.$t('Invalid port'));
return;
}
} else {
port = 80;
}
addr = encodeURIComponent(addrs[0] + ':' + port);
window.open(`/web/${devid}/${addr}/`);
addr = encodeURIComponent(`${ip}:${port}${path}`);
window.open(`/web/${devid}/${addr}`);
}
});
},
Expand Down

0 comments on commit ed85912

Please sign in to comment.