decode url in query-string GET

todo: install target for nginx and systemd files
This commit is contained in:
swirl 2021-08-08 21:33:52 -04:00
parent b05ae723ab
commit 994a47b02e
2 changed files with 10 additions and 2 deletions

View File

@ -44,7 +44,11 @@ A Minimal, SQLite-Backed URL Shortener
| $ curl {{.URL}}/ddg?https://duckduckgo.com
| {{.URL}}/ddg
|
| 5. Deleting a short link
| 5. You can also pass an encoded URL:
| $ curl {{.URL}}?https%3A%2F%2Fduckduckgo.com
| {{.URL}}/1dc4cb37e81de396
|
| 6. Deleting a short link
| $ TMP=$(mktemp)
| $ # temp file will store header
| $ LINK=$(curl -sS {{.URL}} -d https://duckduckgo.com -D $TMP)

View File

@ -171,7 +171,11 @@ func (c controller) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
case http.MethodGet:
st := strings.TrimRight(r.URL.Path, "/")
rq := r.URL.RawQuery
rq, err := url.QueryUnescape(r.URL.RawQuery)
if err != nil {
c.Err(rw, r, err)
return
}
if rq != "" {
u, err := url.Parse(rq)
if err != nil {