feat: support specify path and query for web proxy

Signed-off-by: Jianhui Zhao <zhaojh329@gmail.com>
This commit is contained in:
Jianhui Zhao
2022-05-09 16:51:32 +08:00
parent f8efeafa58
commit ed859122e0
2 changed files with 29 additions and 10 deletions
+12 -2
View File
@@ -239,7 +239,7 @@ 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 {
@@ -247,6 +247,12 @@ func httpProxyRedirect(br *broker, c *gin.Context) {
return
}
path, err := url.Parse(rawPath)
if err != nil {
c.Status(http.StatusBadRequest)
return
}
_, ok := br.devices[devid]
if !ok {
c.Status(http.StatusNotFound)
@@ -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 {
+17 -8
View File
@@ -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}`);
}
});
},