Commit graph

14 commits

Author SHA1 Message Date
Imran Latif
cd69a866d5 Adding method for doing browser redirection from inside any route.
Made some small changes
2015-12-05 02:23:18 +05:00
Imran Latif
d25a611fbd Implemented HTTP HEAD method.
First I tried implementing this solution in such a way that it
explicitly clears body and set `Content-Length` header to body's size.
But for some reason, if I call the URL from cURL then `Content-Length`
header was blank which defeats the very purpose of `HEAD` requests.

I then later anticipated that since `HEAD` would be by-default
implemented by `HTTP::Server` module, there is no need to explicit
clears body and setting `Content-Length` but the way we have written
our previous specs were returning body as well. We could have used some
TestServer kind of thing but if we go to that route we explicitly need
to test non-existent route which I thought would create some
inconsistency among specs.

Crystal has clearly written specs for HEAD requests to make sure body
is not read for them. See
https://github.com/manastech/crystal/commit/acd0b6afb5af438a30529c36b11b
e7954336f23f. I decided to write simple specs which are easy to
maintain in long-run.

We are adding identical HEAD route for every GET route which will make
HEAD requests available for all defined GET requests.

https://github.com/sdogruyol/kemal/issues/19

Added comment for code line which is adding HEAD routes for defined GET routes.
2015-12-04 19:35:14 +05:00
Imran Latif
c42f1f88e9 Added support for magic param _method just like Rails, Sinatra.
Following are the changes made in this commit:

- Added support for magic param `_method` just like Rails, Sinatra
etc.. Browsers which don't support `PUT`, `PATCH` and `DELETE` methods
can simulate them by sending `method` param in request body.

- The default Content-Type to parse request body submitted via forms
etc. is `application/x-www-form-urlencoded`. But if we send Ajax
request in Chrome ($.post) then by-default Content-Type is set to
`application/x-www-form-urlencoded; charset utf-8` which was not
getting matched. I changed the code from `==` to match against a
regular expression using `=~`.

- Print name and color of overridden HTTP method via Logger instead of
printing name and color or request's incoming HTTP method.

Making necessary changes as pointed by @sdogruyol

- Changed method name from`is_override_method_valid?` to
`override_method_valid?`.

- Refactored `if` condition in `override_method_valid?`.
2015-12-03 01:34:16 +05:00
Sdogruyol
171459eee9 Add 500 exception spec 2015-12-01 21:52:44 +02:00
Sdogruyol
e1530f8fd5 Add built-in exception route 2015-11-28 12:39:58 +02:00
Sdogruyol
58013ba005 Add 404 2015-11-27 22:45:13 +02:00
Sdogruyol
3687897005 Added JSON body parsing 2015-11-06 20:24:38 +02:00
Sdogruyol
a0c909621c Renamed all occurrences of ctx to env 2015-10-29 11:49:58 +02:00
Sdogruyol
5376eb8bb2 Added context specs 2015-10-28 20:52:34 +02:00
Sdogruyol
3cc50e0a7e Added param parser 2015-10-28 20:30:27 +02:00
Sdogruyol
a8ad95aa67 Removing redundant code 2015-10-28 18:09:45 +02:00
Sdogruyol
4a6fb6cf66 Now supports multiple query strings 2015-10-26 20:49:28 +02:00
Sdogruyol
efe75196f7 Added request body parsing 2015-10-26 20:25:10 +02:00
Sdogruyol
459f602645 Renamed spec 2015-10-24 19:17:24 +03:00
Renamed from spec/frank_handler_spec.cr (Browse further)