diff --git a/http.go b/http.go index aa33ab2..135bebb 100644 --- a/http.go +++ b/http.go @@ -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 { diff --git a/ui/src/views/Home.vue b/ui/src/views/Home.vue index 03dcbf9..5ca85f4 100644 --- a/ui/src/views/Home.vue +++ b/ui/src/views/Home.vue @@ -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}`); } }); },