rawURL without query AND fragment
@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"net/http"
+ "net/url"
"os"
"sort"
"strconv"
@@ -62,24 +63,20 @@ func NewHTTPContext(baseCtx *hcl.EvalContext, req, bereq *http.Request, beresp *
id = uid
}
- rawUrl := *req.URL
- rawUrl.RawQuery = ""
evalCtx.Variables["req"] = cty.ObjectVal(reqCtxMap.Merge(ContextMap{
"id": cty.StringVal(id),
"method": cty.StringVal(req.Method),
"path": cty.StringVal(req.URL.Path),
- "url": cty.StringVal(rawUrl.String()),
+ "url": cty.StringVal(newRawURL(req.URL).String()),
"query": seetie.ValuesMapToValue(req.URL.Query()),
"post": seetie.ValuesMapToValue(req.PostForm),
}.Merge(newVariable(httpCtx, req.Cookies(), req.Header))))
if beresp != nil {
- rawUrl = *req.URL
- rawUrl.RawQuery = ""
evalCtx.Variables["bereq"] = cty.ObjectVal(ContextMap{
"method": cty.StringVal(bereq.Method),
"path": cty.StringVal(bereq.URL.Path),
- "url": cty.StringVal(rawUrl.String()),
+ "url": cty.StringVal(newRawURL(bereq.URL).String()),
"query": seetie.ValuesMapToValue(bereq.URL.Query()),
"post": seetie.ValuesMapToValue(bereq.PostForm),
}.
@@ -92,6 +89,13 @@ func NewHTTPContext(baseCtx *hcl.EvalContext, req, bereq *http.Request, beresp *
return evalCtx
}
+func newRawURL(u *url.URL) *url.URL {
+ rawURL := *u
+ rawURL.RawQuery = ""
+ rawURL.Fragment = ""
+ return &rawURL
+}
+
func cloneContext(ctx *hcl.EvalContext) *hcl.EvalContext {
c := &hcl.EvalContext{
Variables: make(map[string]cty.Value),
