Commit graph

317 commits

Author SHA1 Message Date
Ben Jolitz
1f809c68c8 Support additional options as part of the Config
This commit adds the ability to add a closure suitable for adding
additional options. It is expected to allow someone to set global,
module or class level variables so they can pass changes/options
suitable for making decisions.
2016-03-30 13:33:51 -07:00
Fatih Kadir Akın
8110788a41 Added return_with macro to break response in the middle of the block. 2016-03-30 00:48:58 +03:00
Serdar Dogruyol
7b1bc43a41 Update dsl.cr 2016-03-23 14:45:18 +02:00
sdogruyol
be418feaf3 Fix WebSocketHandler 2016-03-23 13:21:19 +02:00
Filip Defar
a8ff776b49 Don't convert host_binding to slice when instantiating server 2016-03-22 21:20:21 +01:00
Sdogruyol
fd904cd98d 0.11.0 2016-03-19 15:15:44 +02:00
Sdogruyol
664673f125 Set content-type to text/html on errors.Fixes #130 2016-03-18 20:03:04 +02:00
Fatih Kadir Akın
8402f06bc3 Show backtrace in 500 statuses using inspect_with_backtrace 2016-03-08 13:43:46 +02:00
Serdar Dogruyol
a194bebe31 Merge pull request #123 from f/master
Upgrade ParamParser to make it more convinient.
2016-03-07 13:41:24 +02:00
Fatih Kadir Akın
043d1c8aa2 Add memoization to lazy param parsing 2016-03-07 11:21:37 +02:00
Fatih Kadir Akın
4ee4b66135 Make the param getters lazy to improve performance 2016-03-06 22:29:23 +02:00
Fatih Kadir Akın
42deb95688 Remove merged params to improve performance 2016-03-06 21:46:35 +02:00
Fatih Kadir Akın
53d12534b7 Remove ParamContainer abstraction to make it faster. 2016-03-06 21:43:13 +02:00
Sdogruyol
e3c3154006 Make sure to instantiate null log handler 2016-03-06 20:16:51 +02:00
Fatih Kadir Akın
e53ba1d9da Decouple ParamContainer which makes the code cleaner, and fix kemal.cr
url -- by @sdogruyol
2016-03-06 14:08:59 +02:00
Fatih Kadir Akın
8267ffe2c5 Upgrade ParamParser to make it more convinient.
It now decouples `env.params` to `env.params.query`, `env.params.body`,
`env.params.json` and `env.params.url` and you still can access merged
values using `env.params.all`
2016-03-06 13:22:24 +02:00
Joris Moriau
04ccb973a9 set positions for errors and logger middleware, added 2 views 2016-03-03 21:23:04 +01:00
Armin Pašalić
6759fb2373 Add options to the DSL
As in https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.2 and because it's a nice way to document API
2016-02-25 17:38:57 +01:00
Joris Moriau
8f6b00ba55 decoupled-urlparams-from-routehandler 2016-02-19 12:45:25 +01:00
Joris Moriau
e6d1da6dd2 added small feature 2016-02-17 20:56:19 +01:00
sdogruyol
5a58ee3cbb Format code 2016-02-17 11:52:13 +02:00
Joris Moriau
c5201f01ad added verb for filters and minor improvements 2016-02-17 10:34:01 +01:00
Jerome Gravel-Niquet
69b836a98a use new Kilt 0.3 syntax, add mention in readme for clarity 2016-02-15 12:09:33 -05:00
Joris Moriau
ed769ad700 added configure serve_static 2016-02-15 12:59:26 +01:00
Jerome Gravel-Niquet
9404fa5c80 Abstract template engines with Kilt 2016-02-14 13:37:55 -05:00
Sdogruyol
8c87a3fa67 Replace global macros with methods. Thanks @asterite 2016-02-14 18:52:49 +02:00
Sdogruyol
092f5a2e49 Improve kemal.cr 2016-02-14 15:15:52 +02:00
Joris Moriau
f5b5260ab9 fixed small redundancy. 2016-02-14 13:57:51 +01:00
Joris Moriau
f7975d917d decoupled errors from route-handler 2016-02-14 12:52:32 +01:00
Sdogruyol
88aa9cd497 Remove call_next from RouteHandler 2016-02-14 11:02:16 +02:00
sdogruyol
8f5bc755ae Add logger macro to easily setup custom log_handler 2016-02-12 16:09:15 +02:00
sdogruyol
3c75d727ba Complete decoupling logger 2016-02-12 14:11:34 +02:00
Joris Moriau
3aa22e11c0 - add_filters no longer needs to be called explicitly it will be lazily called if needed.
- the Filter middleware no longer needs to be the first in the handlers array.
- before and after methods will raise an exception if a filter for the requested path is already defined.
2016-02-12 12:03:38 +01:00
sdogruyol
454894820d Fix config 2016-02-12 10:22:52 +02:00
Sdogruyol
850af8819e Start decoupling logger 2016-02-11 23:26:47 +02:00
Sdogruyol
ffc3d6d224 Don't require yaml 2016-02-10 22:02:10 +02:00
Sdogruyol
9de66e2a60 Update CLI wording 2016-02-10 21:58:32 +02:00
TSUYUSATO Kitsune
0f86e59db6 Cache Context#params result 2016-02-10 02:11:18 +09:00
TSUYUSATO Kitsune
55361b3c9a Use 302 to redirect instead of 301
`301` means "Moved Permanently", so browser caches this redirect, it is used when changing server URL.
`302` means "Found", it is used generally (e.g. redirect top page after
login).

Each of `301`, `302`, `303` and `307` means redict, but they are
different. We could choice those status in case.
2016-02-10 00:28:07 +09:00
Sdogruyol
3f3f0d442e Fix Filter namespace 2016-02-07 16:48:49 +02:00
Werner
ab711c22fd Basic filter implementation, similar to Sinatra. 2016-02-07 09:49:38 -04:30
Sdogruyol
467a1b4581 Rename handlers 2016-02-03 22:08:54 +02:00
Aşkın Gedik
8390b96df3 remove unused methods 2016-02-02 17:20:44 +02:00
Serdar Dogruyol
0a1abe9a42 Merge pull request #69 from f/master
Radix-tree already has url param parsing with state-machine implementation which is faster than regex parsing. We don't need regex parsing anymore.
2016-01-26 10:23:39 +02:00
Fatih Kadir Akın
ce1f595c5d Remove param parsing with regex since Radix has state-machine implementation which is a way faster 2016-01-25 22:52:41 +02:00
Serdar Dogruyol
23b09ff645 Merge pull request #68 from f/master
Fix for #67, Radix tree needs path style string
2016-01-25 22:28:25 +02:00
Fatih Kadir Akın
afdb6fb793 Fix for #67, Radix tree needs path style string 2016-01-25 22:22:56 +02:00
Sdogruyol
3b4cdd5323 Rename HTTP::WebSocketHandler::WebSocket to HTTP::WebSocket 2016-01-25 20:56:27 +02:00
Sdogruyol
e223940e5e Replace beryl with f/radix 2016-01-24 20:51:04 +02:00
Fatih Kadir Akın
c14fb3de96 Fix view rendering for Crystal 0.11.0 2016-01-24 19:13:10 +02:00
Sdogruyol
94a73e9ade Update built-in exception route handler 2016-01-24 18:25:21 +02:00
Sdogruyol
02af920a0f Make default content-type text/html 2016-01-24 17:52:24 +02:00
Sdogruyol
fdf38b23c8 Update kemal.cr 2016-01-24 13:31:07 +02:00
Sdogruyol
17f944ef9d Move redirect macro to context def 2016-01-24 12:52:41 +02:00
Sdogruyol
4dd027eb96 Macros spec passing 2016-01-24 12:27:26 +02:00
Sdogruyol
d1f95c0f39 All specs passing except macros 2016-01-24 12:22:25 +02:00
Fatih Kadir Akın
7d0d5add84 Implement radix algorithm for routing (thanks to beryl) 2016-01-22 23:06:13 +02:00
Luis Lavena
df359d66c9 Build Route Regex once to reduce allocations
Right now every `match?` performed against the routes defined result
in a new Regex compiled for the exact same `@path`.

Since `@path` of the Route does not change on every request, we
pre-build it to avoid repeated allocations.

When testing this in release mode (against 0.10.2 [d1e3f0b]):

Before: 32408.48 req/s
After:  34862.07 req/s
2016-01-18 13:48:41 -03:00
Sdogruyol
788c7241d4 Handle cases when logger can be nil 2016-01-18 17:25:52 +02:00
Sdogruyol
0498801b0d Initialize logger in config 2016-01-17 14:22:47 +02:00
Sdogruyol
51092fbb91 Move logger to config 2016-01-17 14:18:18 +02:00
Sdogruyol
2af3648682 Make logger configurable 2016-01-17 13:08:12 +02:00
Sdogruyol
5fb5a4c6ae Small refactor 2016-01-16 12:56:01 +02:00
sdogruyol
7ffa6700de Update CLI to handle missing ssl_key and ssl_cert 2016-01-15 14:50:11 +02:00
Fatih Kadir Akın
37d40f4fbe Implement SSL handling, move option parser to another file to maintain
easier
2016-01-13 23:31:19 +02:00
sdogruyol
b37dd29d4b Update router to handle method matching 2016-01-13 15:22:50 +02:00
sdogruyol
4c423e967f Refactor parse_url_params 2016-01-13 10:07:37 +02:00
Fatih Kadir Akın
3e8b2ae51c Implement parse_url_params 2016-01-13 00:06:19 +02:00
Sdogruyol
0b4a36953f Started reimplementing router 2016-01-12 21:37:12 +02:00
Sdogruyol
aabfe4ff99 Add log macro 2016-01-08 18:44:37 +02:00
Serdar Dogruyol
2503bc4e3d Merge pull request #45 from aladagemre/master
Add 403 view
2016-01-05 19:24:42 +02:00
Ahmet Emre Aladağ
47f505ff76 Update view.cr 2016-01-05 17:35:07 +02:00
sdogruyol
eb4c82043a Add add_handler macro 2016-01-05 14:20:40 +02:00
Sdogruyol
6a4ed2d9eb Add exception logging. Closes #41 2016-01-04 21:54:58 +02:00
Ahmet Emre Aladağ
87bbb2069f Realm added for Basic Authentication 2016-01-04 20:14:05 +02:00
sdogruyol
7ad319c70d v0.6.0 2016-01-03 22:13:10 +02:00
sdogruyol
c21567fe17 Add macro specs 2016-01-03 13:22:43 +02:00
sdogruyol
211685ee74 Fix basic_auth 2015-12-31 14:03:11 +02:00
Serdar Dogruyol
aaa2ee1e31 Add public_folder macro 2015-12-30 20:16:04 +02:00
Sdogruyol
24e2647ed7 Require middleware in bootstrap 2015-12-27 11:59:07 +02:00
Sdogruyol
743fd3682d Add HTTPBasicAuth middleware 2015-12-27 11:53:54 +02:00
Sdogruyol
8b6700695d Update delegate macro in context 2015-12-27 11:17:22 +02:00
Alfonso Uceda Pompa
8c0ea21d44 return raw json when we parse the request body 2015-12-24 17:09:33 +01:00
Alfonso Uceda Pompa
e39770b433 Make compatyble with crystal 0.10.0 2015-12-24 16:25:00 +01:00
Sdogruyol
fbc21b197a Rename to Kemal::WebSocketHandler 2015-12-22 20:51:27 +02:00
Sdogruyol
44af664748 Remove experimental fork mode 2015-12-19 10:00:29 +02:00
Sdogruyol
20ef2b2927 Add more documentation 2015-12-18 22:45:28 +02:00
Serdar Dogruyol
88c19f0051 Remove unnecessary handler 2015-12-16 17:06:06 +02:00
Sdogruyol
06ced7790b Adding websocket support :) 2015-12-15 23:11:21 +02:00
Sdogruyol
66c8b6d857 Move macros from view to macros 2015-12-14 20:05:46 +02:00
Sdogruyol
5c97942707 Add more documentation 2015-12-13 10:25:04 +02:00
Sdogruyol
8522fd2f56 Fix binding 2015-12-12 21:35:17 +02:00
Sdogruyol
58f9d8c590 Add read config from yml 2015-12-12 20:27:46 +02:00
Sdogruyol
85a383b328 Fix static file handler 2015-12-10 21:20:32 +02:00
Sdogruyol
e4da65f1f2 Refactor static file handler 2015-12-10 21:15:28 +02:00
Sdogruyol
21a3c6ad3c Add static file handler 2015-12-10 20:40:39 +02:00
Serdar Dogruyol
12c6af7d79 Merge pull request #32 from ilatif/master
Removed env from redirect and changed redirect from method to macro.
2015-12-09 22:27:04 +02:00
Imran Latif
4d1e31cb41 Removed env from redirect and changed redirect from method to macro.
Removed `env.redirect` in-favor of `redirect` in-order to make Kemal's
API look more like Sinatra.

Thanks @sdogruyol and @f for introducing me to macros :-).

Binding HTTP::Server to 0.0.0.0
2015-12-10 01:24:49 +05:00
Serdar Dogruyol
ef3c16b2c0 Merge pull request #31 from f/master
Add layout support for render macro.
2015-12-09 21:57:01 +02:00
Fatih Kadir Akın
9ade49ae20 Add layout support for render macro. It should be improved in the future. 2015-12-09 17:54:49 +02:00
Serdar Dogruyol
c05db1f643 Remove unnecessary log on exit 2015-12-09 17:36:13 +02:00
Sdogruyol
a67a8508cf Add worker support (experimental) 2015-12-08 22:15:13 +02:00
Serdar Dogruyol
a2a082b58f Merge pull request #29 from askn/master
fix default log color
2015-12-07 10:27:16 +02:00
Sdogruyol
bee7ce2452 Bind host to 0.0.0.0 2015-12-07 09:17:00 +02:00
Aşkın Gedik
fd80fd2f1b fix default log color 2015-12-07 00:21:50 +02:00
Serdar Dogruyol
2ffb4dccdf Merge pull request #27 from f/master
Add render macro to kemal core.
2015-12-06 20:45:53 +02:00
Sdogruyol
aa0d97aa42 Update .travis.yml 2015-12-06 17:56:04 +02:00
Fatih Kadir Akın
945fa59a6c Add render macro to kemal core to have dynamic rendering mechanism. It actually binds built-in ecr parser to the Kemal as a macro. 2015-12-06 16:55:35 +02:00
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
7f198cab3b Remove unnecessary check 2015-12-01 21:47:49 +02:00
Sdogruyol
17fe691710 Add 500 template 2015-11-29 17:32:31 +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
Aşkın Gedik
e284ba8196 add colorize for logger 2015-11-22 20:06:26 +02:00
Sdogruyol
9cb3cafa62 Add flush on newline Fixes #15 2015-11-21 22:53:06 +02:00
Sdogruyol
556247c4ad Revert back to File.write 2015-11-21 00:43:28 +02:00
Sdogruyol
485fed11af Added config env to startup message 2015-11-20 23:12:12 +02:00
Sdogruyol
f66e9cd834 More logger specs 2015-11-20 23:07:10 +02:00
Sdogruyol
0e23e8d9a3 Be sure to close handlers 2015-11-19 20:54:58 +02:00
Sdogruyol
28d4d5167b Updated logger to be more robust 2015-11-18 22:45:49 +02:00
Sdogruyol
bde69e1cdb Changed default mode to development 2015-11-17 21:43:05 +02:00
Sdogruyol
79ef2f30f7 Added environment 2015-11-16 23:55:02 +02:00
Sdogruyol
0e617dcfb6 Removed redundant code for more performant processing 2015-11-15 17:00:51 +02:00
Sdogruyol
fb1d3c3a85 Added handlers to config 2015-11-12 22:48:22 +02:00
Aşkın Gedik
51708ce8e7 parse request body for array 2015-11-10 13:30:16 +02:00
Micah Geisel
dea9b2f663 application/json GETs can have no request body. 2015-11-09 16:35:28 -08:00
Sdogruyol
dc1e6ed4c2 Changed server initialize message 2015-11-08 17:43:53 +02:00
Sdogruyol
3687897005 Added JSON body parsing 2015-11-06 20:24:38 +02:00
Oleksii Fedorov
f658fbe8af Parse request body params only if content type is application/x-www-form-urlencoded 2015-11-05 11:38:06 +01:00
Sdogruyol
c49191e650 Fixed match bug 2015-10-31 09:28:25 +02:00
Sdogruyol
a7cc498dca Refactored context 2015-10-30 22:34:44 +02:00
Sdogruyol
4ce1bc908f Added response and headers 2015-10-30 22:01:18 +02:00
Serdar Dogruyol
ffdaecace4 Added headers to context 2015-10-30 17:06:25 +02:00
Sdogruyol
5892d900ff Added documentation for context, param_parser and route 2015-10-29 17:16:29 +02:00
Sdogruyol
2cbe54b624 Fixed samples url 2015-10-29 11:22:44 +02:00
Sdogruyol
924905f146 Convert parse_request to macro 2015-10-28 22:04:05 +02:00
Sdogruyol
1c53321026 Changed default content-type to text/html 2015-10-28 21:55:17 +02:00
Sdogruyol
a505577d5a Removed response 2015-10-28 20:53:26 +02:00
Sdogruyol
5376eb8bb2 Added context specs 2015-10-28 20:52:34 +02:00
Sdogruyol
ad6baba12b Added param_parser specs 2015-10-28 20:38:24 +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
be58e009af Created logger 2015-10-27 21:01:36 +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
fa00265345 Use macro to generate DSL and support delete,patch verbs 2015-10-24 22:20:39 +03:00
Sdogruyol
cd6f54b714 Removed redundant variable 2015-10-24 19:09:56 +03:00
Sdogruyol
5749a7db60 Formatted 2015-10-23 22:54:18 +03:00
Sdogruyol
5057bd039c Fix typo in require 2015-10-23 22:48:30 +03:00
Sdogruyol
5ca84fea4c Renamed all occurrences to Kemal 2015-10-23 21:33:26 +03:00
Sdogruyol
d23eff9acc Updated to Crystal 0.9.0 2015-10-23 20:55:41 +03:00
Juan Wajnerman
77356f7f43 Route parameters have more precedence than query string arguments 2015-05-29 18:24:31 -03:00
Juan Wajnerman
8b1447b68d Accepts requests with query string 2015-05-29 18:21:15 -03:00
Zamith
8cf04b58ca
Move static file handler to be called after the instance handler
This way only routes that are not caught by the instance handler will go
through to the static file handler.
2015-01-31 14:39:50 +00:00
Ary Borenszweig
5c4eaa99e2 Updated to Crystal 0.5.5 2014-12-14 09:08:16 -03:00
Ary Borenszweig
35a0eac2e9 Updated to Crystal 0.5.2 2014-11-06 14:48:02 -03:00
Ary Borenszweig
889debfd59 Receive Frank::Context and allow setting content-type 2014-07-30 20:50:14 -03:00
Ary Borenszweig
fc4f648c1a Handle POST request, and some refactors 2014-07-30 19:58:48 -03:00
Juan Wajnerman
e601730a0c Frank::Handler instance is not a global variable anymore 2014-07-30 19:27:25 -03:00
Juan Wajnerman
69ed2d4612 Added Frank::Config 2014-07-30 19:17:53 -03:00
Ary Borenszweig
a1c8a1b6f1 Pass array of handlers to HTTP::Server 2014-06-12 13:25:36 -03:00
Juan Wajnerman
d62aa372b3 Added StaticFileHandler to serve files from "public" directory 2014-06-12 11:23:56 -03:00
Juan Wajnerman
c74e7f898b Frank::Handler calls next handlers when the request could not be served 2014-06-12 11:23:35 -03:00
Juan Wajnerman
2eaf44195e Initial commit 2014-06-11 20:41:02 -03:00