Files
PixivFE/utils/partialURL.go
T
iacore c9f3884f92 replace ?r=/redirect_to with something else.
can't shake the fakey feeling. net/http expects one handler max. the way we currently detect redirect param is not one handler.
      we should refactor the code out to be called from different handlers
      also, wtf is /settings/novelFontType?noredirect=t&r=  (redirect or no redirect?)
      suggestion: Use Referer. the header exists for a reason. might need to turn off CSP for that.
2024-08-28 13:39:15 +00:00

51 lines
905 B
Go

package utils
import "fmt"
type PartialURL struct {
Path string
Query map[string]string
}
// Turn `url` into /path?other_key=other_value&`key`=
func unfinishedQuery(url PartialURL, key string) string {
result := fmt.Sprintf("/%s", url.Path)
first_query_pair := true
for k, v := range url.Query {
k = lowercaseFirstChar(k)
if k == key {
continue
}
if v == "" {
// If the value is empty, ignore to not clutter the URL
continue
}
if first_query_pair {
result += "?"
first_query_pair = false
} else {
result += "&"
}
result += fmt.Sprintf("%s=%s", k, v)
}
// This is to move the matched query to the end of the URL
var t string
if first_query_pair {
t = "?"
} else {
t = "&"
}
result += fmt.Sprintf("%s%s=", t, key)
return result
}
func replaceQuery(url PartialURL, key string, value string) string {
return unfinishedQuery(url, key) + value
}