Added more variables + misc

dev
Ice3man543 2021-08-13 20:08:18 +05:30
parent da1630fc21
commit 2ffffbcc04
2 changed files with 14 additions and 5 deletions

View File

@ -2,6 +2,7 @@ package http
import (
"context"
"fmt"
"io"
"io/ioutil"
"net"
@ -251,9 +252,11 @@ func generateVariables(parsed *url.URL, trailingSlash bool) map[string]interface
return map[string]interface{}{
"BaseURL": parsed.String(),
"Domain": domain,
"RootURL": fmt.Sprintf("%s://%s", parsed.Scheme, parsed.Host),
"Hostname": parsed.Host,
"Path": parsed.EscapedPath(),
"Host": domain,
"Port": port,
"Path": parsed.EscapedPath(),
"Scheme": parsed.Scheme,
}
}

View File

@ -24,9 +24,11 @@ func TestVariables(t *testing.T) {
values := generateVariables(parsed, true)
require.Equal(t, values["BaseURL"], parsed.String(), "incorrect baseurl")
require.Equal(t, values["Domain"], "localhost", "incorrect domain name")
require.Equal(t, values["RootURL"], "http://localhost:9001", "incorrect rootURL")
require.Equal(t, values["Host"], "localhost", "incorrect domain name")
require.Equal(t, values["Path"], "/test/123", "incorrect path")
require.Equal(t, values["Port"], "9001", "incorrect port number")
require.Equal(t, values["Scheme"], "http", "incorrect scheme")
require.Equal(t, values["Hostname"], "localhost:9001", "incorrect hostname")
baseURL = "https://example.com"
@ -34,9 +36,11 @@ func TestVariables(t *testing.T) {
values = generateVariables(parsed, false)
require.Equal(t, values["BaseURL"], parsed.String(), "incorrect baseurl")
require.Equal(t, values["Domain"], "example.com", "incorrect domain name")
require.Equal(t, values["Host"], "example.com", "incorrect domain name")
require.Equal(t, values["RootURL"], "https://example.com", "incorrect rootURL")
require.Equal(t, values["Path"], "", "incorrect path")
require.Equal(t, values["Port"], "443", "incorrect port number")
require.Equal(t, values["Scheme"], "https", "incorrect scheme")
require.Equal(t, values["Hostname"], "example.com", "incorrect hostname")
baseURL = "ftp://foobar.com/"
@ -44,9 +48,11 @@ func TestVariables(t *testing.T) {
values = generateVariables(parsed, true)
require.Equal(t, values["BaseURL"], parsed.String(), "incorrect baseurl")
require.Equal(t, values["Domain"], "foobar.com", "incorrect domain name")
require.Equal(t, values["Host"], "foobar.com", "incorrect domain name")
require.Equal(t, values["RootURL"], "ftp://foobar.com", "incorrect rootURL")
require.Equal(t, values["Path"], "", "incorrect path")
require.Equal(t, values["Port"], "", "incorrect port number") // Unsupported protocol results in a blank port
require.Equal(t, values["Scheme"], "ftp", "incorrect scheme")
require.Equal(t, values["Hostname"], "foobar.com", "incorrect hostname")
}