vibe-d / vibe.d

Official vibe.d development
MIT License
1.15k stars 286 forks source link

Allow empty `queryParam` field #2273

Open CosmicToast opened 5 years ago

CosmicToast commented 5 years ago

Consider the case of a single (optional) query parameter without any id, like so: /endpoint?value

Currently, there's no way to actually catch/parse that without directly using .queryString, or doing some weird logic to .query. If one looks at .query contents, it seems like the parser assumes a scenario like /endpoint?value&key2=value2 to mean this:

k v
value
key2 value2

Since DictonaryList is guaranteed to preserve order, this should not be particularly complex.

thaven commented 5 years ago

If one looks at .query contents, it seems like the parser assumes a scenario like /endpoint?value&key2=value2 to mean this:

k v
value
key2 value2

And that is what it actually means.

CosmicToast commented 5 years ago

So certainly, having something along the lines of...

@queryParam("field")
void getX(string field) {
    logInfo(field);
}

be equivalent to

void getX(HTTPServerRequest req) {
    string field;
    if (req.query.length > 0) field = req.query.byKey.front;
    // any (other?) static checks present in queryParam
    logInfo(field);
}

Isn't much of a stretch then?