mirror of
https://github.com/LBRYFoundation/tracker.git
synced 2025-08-23 17:47:29 +00:00
bittorrent: make invalid query escape errors static
This commit is contained in:
parent
2764717657
commit
6e1cfa18d8
1 changed files with 18 additions and 2 deletions
|
@ -5,6 +5,8 @@ import (
|
||||||
"net/url"
|
"net/url"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
log "github.com/Sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Params is used to fetch (optional) request parameters from an Announce.
|
// Params is used to fetch (optional) request parameters from an Announce.
|
||||||
|
@ -39,6 +41,10 @@ var ErrKeyNotFound = errors.New("query: value for the provided key does not exis
|
||||||
// with invalid length.
|
// with invalid length.
|
||||||
var ErrInvalidInfohash = ClientError("provided invalid infohash")
|
var ErrInvalidInfohash = ClientError("provided invalid infohash")
|
||||||
|
|
||||||
|
// ErrInvalidQueryEscape is returned when a query string contains invalid
|
||||||
|
// escapes.
|
||||||
|
var ErrInvalidQueryEscape = ClientError("invalid query escape")
|
||||||
|
|
||||||
// QueryParams parses a URL Query and implements the Params interface with some
|
// QueryParams parses a URL Query and implements the Params interface with some
|
||||||
// additional helpers.
|
// additional helpers.
|
||||||
type QueryParams struct {
|
type QueryParams struct {
|
||||||
|
@ -113,11 +119,21 @@ func parseQuery(query string) (q *QueryParams, err error) {
|
||||||
}
|
}
|
||||||
key, err = url.QueryUnescape(key)
|
key, err = url.QueryUnescape(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
// QueryUnescape returns an error like "invalid escape: '%x'".
|
||||||
|
// But frontends record these errors to prometheus, which generates
|
||||||
|
// a lot of time series.
|
||||||
|
// We log it here for debugging instead.
|
||||||
|
log.WithFields(log.Fields{"error": err}).Debug("failed to unescape query param key")
|
||||||
|
return nil, ErrInvalidQueryEscape
|
||||||
}
|
}
|
||||||
value, err = url.QueryUnescape(value)
|
value, err = url.QueryUnescape(value)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
// QueryUnescape returns an error like "invalid escape: '%x'".
|
||||||
|
// But frontends record these errors to prometheus, which generates
|
||||||
|
// a lot of time series.
|
||||||
|
// We log it here for debugging instead.
|
||||||
|
log.WithFields(log.Fields{"error": err}).Debug("failed to unescape query param value")
|
||||||
|
return nil, ErrInvalidQueryEscape
|
||||||
}
|
}
|
||||||
|
|
||||||
if key == "info_hash" {
|
if key == "info_hash" {
|
||||||
|
|
Loading…
Add table
Reference in a new issue