joaotavora / snooze

Common Lisp RESTful web development
207 stars 23 forks source link

Header and query parameter regressions #16

Open GertThiel opened 5 years ago

GertThiel commented 5 years ago

Hi João.

The TechEmpower Framework Benchmark (or TFB for short) guides many people who are looking for a web framework for their next project. Common Lisp was totally absent until now.

Last weekend I finished adding Eitaro Fukamachi's Woo to the TFB (pull requests 4684 and 4690).

Now I'm adding Snooze to the TFB. And found a few regressions.

TFB is quite demanding e.g. has dedicated expectations how a framework must react to requests.

The Fortunes tests UTF-8 encoded HTML but disallows <meta> tag:

xviii. The response content type must be set to text/html; charset=utf-8.

Because snooze:defroute fortunes (:get "text/html; charset=UTF-8") does not work, I have to resort to patching the response (and adding another Server header by the way).

The Multiple Database Queries and the Database Updates has requirements Snooze can't comply with:

iii. The queries parameter must be bounded to between 1 and 500. If the parameter is missing, is not an integer, or is an integer less than 1, the value should be interpreted as 1; if greater than 500, the value should be interpreted as 500.

I have

(snooze:defroute queries (:get "application/json" &key (queries 1))
  (jonathan:to-json (get-some-random-records (ensure-integer-is-between-one-and-five-hundreds queries))))

(snooze:defroute updates (:get "application/json" &key (queries 1))
  (jonathan:to-json (get-and-update-some-random-records (ensure-integer-is-between-one-and-five-hundreds queries))))

and ensure-integer-is-between-one-and-five-hundreds can handle an erroneous request like GET localhost:8080/queries=FOO but not GET localhost:8080/queries= (parameter with an empty value).

I consider that a bug because query parameters with empty values are quite normal e.g. in data table filter builders.

You find my complete source code in my related GitHub repository.

Can you help?

Thank in advance.

Gert

joaotavora commented 5 years ago

Hi Gert,

Free tests! Thanks a bunch! I will go over these one by one as soon as I can find the time, I'm very busy until the middle of next week.

Just to clear up, you seem to have found two separate bugs (or non-conformities):

  1. You seem to want to create a route that matches a request for a certain resource in the text/html content type with utf-8 as a charset specifically. That is, it should be a different route than the same resource presented with text/html and, say latin-1. Is this what you want? Or would it suffice that Snooze responds with utf-8 by default?

  2. I don't quite understand this second problem. Is it just a case that you want ?queries= to have the same effect as ?queries=1?

GertThiel commented 5 years ago

Hi João.

Since you have limited time to spare I rephrase this issue to guide you to the most important thing first and only:

Situation:

I have:

(snooze:defroute queries (:get "application/json" &key (queries 1))
  (jonathan:to-json (get-some-random-records (ensure-integer-is-between-one-and-five-hundreds queries))))

Expectation:

Every request

shall call my handler with the queries parameter and it's value 1, "FOO" or nil.

Bug:

does not even call my handler. I get no chance to fix the parameter.

Snozze must not repair the query variable. That's not the domain of a router, but my application's responsibility.


Please ignore every other regression in my original post.