Open MatrixDev opened 5 months ago
@Net-burst to look at whether this is an issue for PBS-Java as well
This issue somewhat affects PBS-Java as of Java 20. PBS will just fail due to URL being malformed and won't be sending anything using non-compliant URL. @SerhiiNahornyi @And1sS FYI
You're able to specify the same query param multiple times in the query string. When pulling this info from the query string you should get an array of all of the values for that param. In this case we would make the query param name singular.
https://pkg.go.dev/net/url#ParseQuery
We should support the old format as well.
@bsardo I'd like to clarify few things before start implementation:
// GET {endpoint}?request-id=req1&request-id=req2&imp-id=imp1&imp-id=imp2&imp-id=imp3
With corresponding changes in all comments and docs.
// HTTPFetcherConfig configures a stored_requests/backends/http_fetcher/fetcher.go
type HTTPFetcherConfig struct {
Endpoint string `mapstructure:"endpoint"`
AmpEndpoint string `mapstructure:"amp_endpoint"`
UseLegacyRequestBuilder `mapstructure:"use_legacy_request_builder"` // ???
}
Also, legacy request builder will have correctly encoded symbols using url.QueryEscape
FetchAccounts
function has the same problem with incorrectly encoded symbols. I assume it should follow the same logic.There's a potential bug in FetchCategories
function.
Endpoint could be with or without params embedded:
urlPrefix := endpoint
if strings.Contains(endpoint, "?") {
urlPrefix = urlPrefix + "&"
} else {
urlPrefix = urlPrefix + "?"
}
return &HttpFetcher{
client: client,
Endpoint: urlPrefix,
}
In FetchCategories
function we are assuming that there could be only Endpoints without params:
var dataName, url string
if publisherId != "" {
dataName = fmt.Sprintf("%s_%s", primaryAdServer, publisherId)
url = fmt.Sprintf("%s/%s/%s.json", strings.TrimSuffix(fetcher.Endpoint, "?"), primaryAdServer, publisherId)
} else {
dataName = primaryAdServer
url = fmt.Sprintf("%s/%s.json", strings.TrimSuffix(fetcher.Endpoint, "?"), primaryAdServer)
}
E.g. if Endpoint looks like this:
http://requests.endpoint.com/requests?foo=bar&
it will result in something like this:
http://requests.endpoint.com/requests?foo=bar&/primaryAdServer/pubId.json
Ideally, we should use the domain of the Endpoint here. Or at least replace strings.TrimSuffix
with strings.Split(fetcher.Endpoint, "?")[0]
.
WDYT?
From the Go server documentation (
stored_requests/backends/http_fetcher/fetcher.go
):Below is an example of the actual request from the PBS to endpoint:
But according to RFC 3986 this is not a valid URI format because query cannot contain
[
,]
nor"
characters:This causes problems when implementing stored requests endpoints with strict frameworks like Actix / Axum (probably others as well).
As a quick hack this fixes the problem but most probably it should be implemented by properly encoding query arguments: