Commit graph

331 commits

Author SHA1 Message Date
TJ Holowaychuk
15ab936001 change .status default to 404. Closes #263 2014-04-28 21:17:46 -07:00
dead_horse
48ac0669c5 fix content-length when body is re-assigned. Closes #267 2014-04-28 20:34:26 -07:00
TJ Holowaychuk
952dca336d rename setType -> getType
sounds weird
2014-04-28 20:12:53 -07:00
Jonathan Ong
163e59c0d5 refactor to use set-type 2014-04-27 01:53:07 -07:00
Jonathan Ong
0cacc5706a use koa-is-json 2014-04-25 00:15:33 -07:00
TJ Holowaychuk
94dd87741e ocd 2014-04-24 17:58:37 -07:00
dead_horse
6a2ed3e6eb assert object type in ctx.onerror 2014-04-25 08:34:11 +08:00
dead_horse
5de9d962a0 remove unused debug 2014-04-25 00:07:37 +08:00
Jonathan Ong
e472a18010 refactor: use mime-extended 2014-04-19 07:45:57 -07:00
TJ Holowaychuk
74cb04e7c1 refactor 2014-04-15 08:39:40 -07:00
TJ Holowaychuk
0a954c8d99 ocd 2014-04-15 08:35:10 -07:00
dead_horse
b06bb3cb85 simplify respond 2014-04-15 23:31:11 +08:00
TJ Holowaychuk
990caf4e71 refactor 2014-04-14 15:36:39 -07:00
TJ Holowaychuk
95a78c3a44 Merge pull request #255 from dead-horse/stream-body
make sure all intermediate stream bodies will be destroy
2014-04-14 15:34:13 -07:00
dead_horse
69c82f63b5 fix length when .body is missing 2014-04-13 11:35:28 +08:00
TJ Holowaychuk
bb0a0b3659 ocd 2014-04-12 10:59:04 -07:00
dead_horse
64aad129d3 fix this.status= in this.body
fix default status set bug in this.body=null.
do not call this.status= if this.status exist.
make sure empty content status remove content headers
2014-04-10 11:47:30 +08:00
TJ Holowaychuk
3d8ab61fa1 change res.type= to always default charset. Closes #252 2014-04-09 09:34:50 -07:00
dead_horse
329d2b94db make sure all intermediate stream bodies will be destroy and have error handle 2014-04-10 00:02:13 +08:00
TJ Holowaychuk
dfe8e95be4 remove ctx.inspect() implementation. Closes #164
obscures user-defned properties. ideally we fix it so .req / .res are not so verbose but meh for now
2014-04-05 19:15:14 -07:00
Dmitry Mazuro
9e8d6a3aa0 ocd 2014-03-24 21:21:15 +03:00
Jonathan Ong
52cb57cc7e fix overwriting of content-type w/ HEAD requests 2014-03-23 04:01:14 -07:00
Jonathan Ong
c382305d4f refactor: use escape-html
dat SLOC
2014-03-12 18:30:16 -07:00
Jonathan Ong
182f9d6fa4 refactor: use statuses 2014-03-12 18:29:14 -07:00
TJ Holowaychuk
9b1651a8e6 fix inspection of app. Closes #108 2014-03-11 11:06:57 -07:00
TJ Holowaychuk
895cf4040c add app.toJSON() 2014-03-11 11:01:33 -07:00
New Now Nohow
0a223f2bb7 Let errors provide their own status.
When calling `ctx.throw`, you're allowed to provide an error object and a
status code. The status code is later set as the `status` property of the error
object. If no status code is provided, it defaults to 500. However, this
happens even if the error object already had a `status` property.

This commit allows an error's pre-existing `status` property to be used in
conjunction with `ctx.throw`.

If the status code is below 500, the error message will be exposed to the user
in the HTTP response. It would be nice to have some Error subclasses that
always have the same status code, because then we could just write
`ctx.throw(new WhateverError())`, and define which 4xx error code we want in
the definition of `WhateverError` itself. If, for example, an
`AuthenticationError` is always meant to go along with a 401, then it would be
nice to just have that knowledge in the class definition.
2014-03-06 22:54:25 -05:00
TJ Holowaychuk
b1f0abd16d Revert "add response.charset accessor and ctx.charset alias"
This reverts commit 94413b1bd4.
2014-03-06 18:05:01 -08:00
TJ Holowaychuk
c50012a636 Merge pull request #225 from dead-horse/issue224-host-confused
add request.hostname(getter), fixed #224
2014-02-26 10:54:40 -08:00
Robert Sköld
e77e5a4bdc Debug name koa:context -> koa:request 2014-02-26 09:51:45 +01:00
dead_horse
72a9b69146 add request.hostname(getter), fixed #224
make request.host and request.hostname work as node url lib
http://nodejs.org/api/url.html#url_url
this commit will change older request.host(getter)
2014-02-26 14:03:05 +08:00
Jonathan Ong
cb532b7bef this.writable to check if the socket is writable
because node sucks haha
2014-02-15 02:06:08 -08:00
TJ Holowaychuk
785aba879c add request.charset 2014-02-14 09:38:59 -08:00
TJ Holowaychuk
94413b1bd4 add response.charset accessor and ctx.charset alias 2014-02-14 09:33:10 -08:00
TJ Holowaychuk
08149052fa change ctx.length and ctx.type to always delegate to response object [breaking change] 2014-02-14 09:16:39 -08:00
Jonathan Ong
c7ff0e2ac1 response.body: fix html content sniffing for strings
closes #214
2014-02-13 18:35:25 -08:00
TJ Holowaychuk
aa08845c70 remove app.jsonSpaces setting. Closes #202 2014-01-31 18:39:47 -08:00
Jonathan Ong
ea5757ff57 remove app.keys getter/setter
closes #203
2014-01-31 16:09:29 -08:00
Jonathan Ong
c5655e093a bump cookies to 0.4.0
no longer need to do that keygrip stuff, though i’m more inclined to
remove all the error checking.
2014-01-31 13:52:27 -08:00
TJ Holowaychuk
3a50280445 Merge pull request #200 from koajs/fix/ctx.onerror
context.onerror: fix response handling
2014-01-24 15:03:02 -08:00
Jonathan Ong
2bc3bb7327 this.respond=false for bypassing koa's response handling
closes #198
2014-01-24 14:38:40 -08:00
Jonathan Ong
2d1147ed21 context.onerror: fix response handling
closes #199
2014-01-24 14:29:57 -08:00
TJ Holowaychuk
0610a841df change ctx.throw() to no longer .expose 5xx errors. Closes #197 2014-01-20 18:44:07 -08:00
pana
30d200dc09 remove the vary method from request object 2014-01-17 18:19:51 +08:00
Jonathan Ong
ea1a631bb1 bump finished and mocha 2014-01-16 22:33:02 -08:00
TJ Holowaychuk
3bb7a63b77 ocd 2014-01-13 06:36:49 -08:00
TJ Holowaychuk
53b1b8133c refactor with delegation utility 2014-01-13 06:36:10 -08:00
TJ Holowaychuk
26fb6a138a add ctx.host= delegate 2014-01-07 17:22:46 -08:00
jeromew
93351bf845 Add req.host= 2014-01-07 21:09:01 +00:00
Veselin Todorov
6cd4c776f8 context.throw supports Error instances 2014-01-04 10:28:24 +02:00
Jonathan Ong
3eb894ee85 res: 205 is a no body response code too!
not sure anyone cares enough about this for a test. plus, it’ll still
“work”
2013-12-30 22:25:44 -08:00
TJ Holowaychuk
dc96d9828b refactor Response#status= 2013-12-30 10:04:34 -08:00
TJ Holowaychuk
41502429de Merge pull request #163 from koajs/404
better 404 handling
2013-12-30 10:02:23 -08:00
Jonathan Ong
e71937491b refactor: remove unused argument 2013-12-29 22:33:59 -08:00
Jonathan Ong
b7b1c0fd44 better 404 handling 2013-12-29 22:26:19 -08:00
Jonathan Ong
51da356a5f debug: check for fn._name as well 2013-12-29 16:04:06 -08:00
TJ Holowaychuk
7c3181e4d7 fix ctx.inspect() after previous commit
otherwise .body will be missing
2013-12-29 11:20:51 -08:00
TJ Holowaychuk
14fe56e632 add explicit .toJSON() calls to ctx.toJSON() 2013-12-29 10:19:21 -08:00
TJ Holowaychuk
88fb4c841d remove trailing comma 2013-12-29 05:46:12 -08:00
Jonathan Ong
20615b808d refactor: move .is to type-is 2013-12-27 18:56:09 -08:00
Jonathan Ong
7fe4133b4a refactor: move content negotiation to accepts 2013-12-27 18:56:02 -08:00
Jonathan Ong
0d9336622c use yield *next internally 2013-12-22 14:48:28 -08:00
mako-taco
9fe483ca76 handle manually written responses 2013-12-22 14:46:36 -08:00
TJ Holowaychuk
87c03aff61 add support for .throw(status, msg). Closes #130 2013-12-20 15:34:16 -08:00
Jonathan Ong
879293f548 use on-socket-error 2013-12-20 14:39:53 -08:00
Jonathan Ong
61d437d746 remove next in callback for now
revisit mounting later
2013-12-19 23:13:37 -08:00
Jonathan Ong
38d5bad4d1 bumpity boop co 2013-12-19 22:33:35 -08:00
Jonathan Ong
938a67c94f lint: remove unused requires
duh.
2013-12-19 21:16:19 -08:00
Jonathan Ong
34104c9af3 refactor: allow any streams with .pipe method 2013-12-19 21:14:47 -08:00
TJ Holowaychuk
70971dcb53 add GeneratorFunction assertion for app.use(). Closes #120
breaks old old shit but thats ok, super early in the game
2013-12-19 10:03:08 -08:00
TJ Holowaychuk
171892c669 fix: cleanup socker error handler on response 2013-12-19 08:53:48 -08:00
Eivind Fjeldstad
ddde5f96ef add deprecation warning for ctx.error
Didn't notice the change until now. A warning would be useful
2013-12-19 11:48:32 +01:00
TJ Holowaychuk
1769f9c431 add socket error-handling. Closes #114 2013-12-17 17:37:35 -08:00
Jonathan Ong
0c330ffb1a lint: remove unused references, fix global leak 2013-12-09 01:53:18 -08:00
TJ Holowaychuk
e78349a73d refactor ctx.toJSON() to recurse. Closes #108 2013-12-02 09:08:01 -08:00
TJ Holowaychuk
a2582e7aa3 change req.is() to return the canonical mime type 2013-11-28 12:47:23 -08:00
TJ Holowaychuk
5dfadba96f remove null return from .is() 2013-11-28 12:39:45 -08:00
TJ Holowaychuk
48601ea7d8 add matchesMime() util 2013-11-28 12:38:35 -08:00
TJ Holowaychuk
271d921c41 change an .is() example
text/* already covers it
2013-11-28 12:29:28 -08:00
Jonathan Ong
8717a3ad2b req.is(): make better
closes #105 and #106
2013-11-28 00:13:16 -08:00
TJ Holowaychuk
309f2ac00e add debug() for .listen() and .keys= 2013-11-26 21:26:05 -08:00
Jonathan Ong
e447e731b6 req.acceptsLanguage - default to first type fi header not set 2013-11-26 14:52:24 -08:00
Jonathan Ong
c24ab00b23 req.acceptsCharsets - default to first type if header not set 2013-11-26 14:49:07 -08:00
TJ Holowaychuk
8e10f12d38 add ctx.remove() and res.remove(). Closes #100 2013-11-24 05:06:35 -08:00
Jonathan Ong
1d38d4acd1 req.accepts: default to first 'type' 2013-11-20 18:00:24 -08:00
Jonathan Ong
5ae3f4eb30 req.acceptsEncodings: default to 'identity' 2013-11-20 17:46:11 -08:00
Jonathan Ong
9d7dd437d7 context delegates: response.lastModified and response.etag
only doing setters because i think getters would be pretty confusing.
2013-11-20 14:09:49 -08:00
Jonathan Ong
1dd1d02db0 app.respond: support 205 status codes as no-content
pretty new to me, but it’s basically the same as 204
2013-11-19 22:20:17 -08:00
Jonathan Ong
28ca80758b ctx.search and ctx.request.search 2013-11-18 19:29:29 -08:00
Jonathan Ong
7d9c6ba66c context: .error() -> .throw()
.error() still works for compatibility, but it will be removed in the
future. closes #94
2013-11-18 17:38:12 -08:00
Jonathan Ong
b88babe5ee refactor context: move the non-delegated properties up 2013-11-18 17:33:41 -08:00
Jonathan Ong
9407d7776c context: cross-reference request and response 2013-11-18 14:10:11 -08:00
TJ Holowaychuk
cb682ed904 add body.close check for HEAD requests 2013-11-15 11:33:14 -08:00
TJ Holowaychuk
27d1336af5 Merge pull request #89 from koajs/keygrip
add keygrip support
2013-11-15 11:31:23 -08:00
TJ Holowaychuk
f3a6f6ae39 fix stream leak on HEAD. Closes #91 2013-11-15 10:49:28 -08:00
TJ Holowaychuk
f4b7f279ea ocd 2013-11-15 10:09:56 -08:00
Jonathan Ong
0362c8e457 add app.keys support 2013-11-15 10:04:07 -08:00
Jonathan Ong
18c2cd1dac this.originalUrl && this.request.originalUrl 2013-11-14 14:18:05 -08:00
TJ Holowaychuk
d23ad1a024 add .body to Response#inspect() 2013-11-14 11:34:55 -08:00
TJ Holowaychuk
35a0c1d2bb add {request,response,context}#toJSON() 2013-11-14 11:30:56 -08:00
TJ Holowaychuk
db22fba86d Merge branch 'master' of github.com:koajs/koa 2013-11-14 11:23:17 -08:00
TJ Holowaychuk
64fa0b5c2a Merge pull request #85 from koajs/expose-proto
Expose proto
2013-11-14 11:23:10 -08:00
TJ Holowaychuk
d247e7835c Merge branch 'master' of github.com:koajs/koa 2013-11-13 21:11:28 -08:00
Jonathan Ong
e51e85e0fc response.etag: remove getter for now
until we figure out a good way to return both weak and strong validators
2013-11-13 21:04:40 -08:00
TJ Holowaychuk
088fcfd3a6 refactor res.etag= regexp 2013-11-13 20:48:57 -08:00
Jonathan Ong
2f74207e6c response.etag and response.lastModified 2013-11-13 19:59:49 -08:00
Jonathan Ong
0be1442111 expose app-specific prototypes, cleanup/fix tests 2013-11-13 18:41:40 -08:00
TJ Holowaychuk
93f1bce66f fix ctx.ip
need tests for this
2013-11-13 13:17:16 -08:00
TJ Holowaychuk
c699c75c52 add koa Request / Response objects and delegation. Closes #52 2013-11-13 09:01:15 -08:00
Jonathan Ong
ee6dce83af ctx.redirect(): only set status code if not already a valid redirect status code
specifically 3xx codes except for 304. closes #66
2013-11-08 16:25:03 -08:00
TJ Holowaychuk
3dd172d032 remove content-negotiation accessor methods, replace with method equivalents 2013-11-08 15:16:51 -08:00
TJ Holowaychuk
cf580dbaf3 remove trailer methods
less common than .auth which we removed as well but we can
add them back if it becomes a common request
2013-11-08 14:40:58 -08:00
TJ Holowaychuk
8b64343813 remove a few redundant methods for header field values 2013-11-08 14:39:20 -08:00
TJ Holowaychuk
9778933e25 Merge branch 'master' of github.com:koajs/koa 2013-11-08 14:38:42 -08:00
TJ Holowaychuk
770183771e add docs for .headersSent alias 2013-11-08 14:38:35 -08:00
Jonathan Ong
accb1d6a61 pass an optional next to app.callback() 2013-11-08 01:17:41 -08:00
Jonathan Ong
2a7b6d07bf remove unused var 2013-11-08 01:14:43 -08:00
Jonathan Ong
1bcf9b413f remove unnecessary closure 2013-11-08 01:04:26 -08:00
TJ Holowaychuk
c1bed668bd remove app.context() for now
get away from promoting the extension of prototypes, aside
from it looking better there isnt really a compelling reason
to allow this
2013-11-07 17:05:26 -08:00
TJ Holowaychuk
2d35cdff50 add new style middleware support through @jonathanong's koa-compose patch 2013-11-07 16:15:47 -08:00
Jonathan Ong
3c3b81b960 Merge pull request #60 from jonathanong/warn-context-overwrite
debug context: notify if a property is being overwritten
2013-10-25 03:49:23 -07:00
Jonathan Ong
f961647377 add additional node.js aliases 2013-10-23 23:54:07 -07:00
Jonathan Ong
fbfeffa090 statusCode alias for status
for node
2013-10-23 23:44:22 -07:00
Jonathan Ong
6492f2ca4a headersSent alias for headerSent
i like keeping things as similar to node as possible :)
2013-10-23 22:38:06 -07:00
Jonathan Ong
cb60fb872a only listen to stream errors if not already 2013-10-14 22:40:02 -07:00
TJ Holowaychuk
1810977700 update co to 2.0 2013-10-14 16:50:05 -07:00
TJ Holowaychuk
3b2c55b68b add overriding to application/json on ctx.body=object
since it cant be anything else, but if you have middleware that transforms
the object to xml or something then you could set ctx.type=
2013-10-10 12:48:14 -07:00
TJ Holowaychuk
3b7a7b5047 Merge pull request #58 from jonathanong/set-body-length
set length on body override
2013-10-10 12:41:41 -07:00
Jonathan Ong
ada1be13bc Merge pull request #56 from jonathanong/bind-onerror
bind .onerror to context
2013-10-10 11:11:38 -07:00
Jonathan Ong
50d73e3709 onerror: check existence of error 2013-10-08 23:23:14 -07:00
Jonathan Ong
df367e0749 debug: notify if a property is being overwritten 2013-10-05 12:56:36 -07:00
Jonathan Ong
98a386a485 bind .onerror to context 2013-10-05 12:32:05 -07:00
Jonathan Ong
0e829c17ad set length on body override 2013-10-05 12:31:48 -07:00
Jonathan Ong
4aa75a1164 cleanup trailing whitespace in .js files 2013-10-05 12:27:15 -07:00
TJ Holowaychuk
83fd83aaf8 fix ctx.body= content-type override check. Thanks @jonathanong 2013-09-15 08:51:56 -07:00
TJ Holowaychuk
11913f5e4e add ctx.body= setter
this prevents a bunch of redundant checks that middleware may need to
check response length, type etc. the less code floating around based
on our supported response body types the better, giving us more freedom
to change these as needed, and just less error-prone code in general.
2013-09-14 15:54:17 -07:00
TJ Holowaychuk
04f4d72692 add charset support to ctx.type= 2013-09-14 14:48:33 -07:00
TJ Holowaychuk
167530a9e6 add a todo 2013-09-13 21:06:16 -07:00
TJ Holowaychuk
7a26886040 change app.onerror to ignore 404s
so you can easily unwind the stack for 404s
2013-09-13 20:54:52 -07:00
TJ Holowaychuk
fc25b79b99 add err.expose check for response handler to expose the err.message 2013-09-12 08:05:50 -07:00
TJ Holowaychuk
6db24f9fac change ctx.error() to flag as err.expose
meaning the application could respond with this message if it likes
2013-09-12 08:01:40 -07:00
TJ Holowaychuk
091d5010cd add ENOENT err.code support for 404 2013-09-08 12:11:02 -07:00
TJ Holowaychuk
228c38cf3e fix text/plain response for 500 errors 2013-09-08 12:07:50 -07:00
TJ Holowaychuk
92b741ac0a remove socket error handling, use server "clientError" 2013-09-08 11:44:45 -07:00
TJ Holowaychuk
cf54f7d7d5 remove a console.log 2013-09-08 11:41:52 -07:00
TJ Holowaychuk
2fe83a4e3d add failing socket error handling test 2013-09-08 11:41:43 -07:00
TJ Holowaychuk
02ae4f787d fix socket "error" handling
always has clientError now
2013-09-08 11:27:16 -07:00
TJ Holowaychuk
67b49cf82d remove unnecessary .bind() 2013-09-08 09:37:33 -07:00
TJ Holowaychuk
f6161918ee Merge branch 'master' of github.com:koajs/koa 2013-09-02 18:29:04 -07:00
Karl Böhlmark
520df772ef use byteLength when calculating content-length 2013-09-02 23:55:38 +02:00
TJ Holowaychuk
7754a3535a move downstream logic to response middleware 2013-09-01 16:27:03 -07:00
TJ Holowaychuk
a1edb2fe7c add docs for error ctx 2013-08-31 09:18:43 -07:00
TJ Holowaychuk
b3761b5da0 Merge branch 'master' of github.com:koajs/koa 2013-08-31 09:17:16 -07:00
Jonathan Ong
a5208f5ce6 pass context to errors
errors are kind of useless without the context
2013-08-30 23:48:54 -07:00
Kim Joar Bekkelund
baefcacff9 typo 2013-08-30 23:09:18 +02:00
TJ Holowaychuk
32d65cfe91 add basic instrumentation 2013-08-28 21:10:25 -07:00
TJ Holowaychuk
fae98c10ec add context debug() 2013-08-27 21:24:53 -07:00
TJ Holowaychuk
ddc7347afe change "unnamed" middleware to -, less junk output 2013-08-27 21:23:11 -07:00
TJ Holowaychuk
ad0dd3cc39 add Context#error(). Closes #31 2013-08-27 20:54:13 -07:00
TJ Holowaychuk
99895aa215 change app to emit "error" events instead of app.error(fn) 2013-08-27 20:24:04 -07:00
TJ Holowaychuk
eb41a90b80 fix app-level error delegation, always delgate 2013-08-27 19:42:45 -07:00
TJ Holowaychuk
b047405cc5 add Context#hasContent 2013-08-27 19:30:35 -07:00
TJ Holowaychuk
9e69922859 replace "qs" with native "querystring" for now 2013-08-27 14:49:11 -07:00
TJ Holowaychuk
6fb32165e3 fix .status= case sensitivity 2013-08-22 21:10:59 -07:00
TJ Holowaychuk
3439437c18 add app.error(fn). Closes #4 2013-08-22 18:47:07 -07:00
TJ Holowaychuk
d2713418cc add .querystring memoization 2013-08-22 18:07:16 -07:00
TJ Holowaychuk
261acbde88 add .query memoization for ultimate hello world benchmarks 2013-08-22 18:06:16 -07:00
TJ Holowaychuk
933ecd8747 add memoization to .path. Closes #17 2013-08-22 17:58:51 -07:00
TJ Holowaychuk
832a1dcc1e change socket error listener to just use length 2013-08-22 11:53:14 -07:00
TJ Holowaychuk
4e4fcfc642 fix socket error handler event listener leak 2013-08-22 11:52:22 -07:00
TJ Holowaychuk
fe89dc3783 add socket error-handling. Closes #6
otherwise node just explodes, not a good default
2013-08-21 19:52:01 -07:00
TJ Holowaychuk
b4b0789d7a fix .onerror bind for stream "error" handling 2013-08-21 19:50:32 -07:00
TJ Holowaychuk
9d7720f2d8 change .outputErrors to false for "test" env only
good to know in prod ;)
2013-08-21 19:48:47 -07:00
TJ Holowaychuk
2de010ca47 add err.status support. Closes #20 2013-08-21 19:47:56 -07:00
TJ Holowaychuk
ca7be7b89f add Context#cookies support. Closes #7
need to add signing support in there as well
2013-08-20 21:51:14 -07:00
TJ Holowaychuk
1457a3df0f add striping of Content-* fields when 204 / 304. Closes #21 2013-08-20 21:24:18 -07:00
TJ Holowaychuk
3d92717b7a remove Context#auth. Closes #26 2013-08-19 18:24:17 -07:00
TJ Holowaychuk
607f2fda8f docs 2013-08-18 11:15:22 -07:00
TJ Holowaychuk
8ccfc14e88 add createContext() 2013-08-18 11:14:01 -07:00
Jonathan Ong
978f581099 app.context: extend the context with your own properties 2013-08-17 16:58:53 -07:00
TJ Holowaychuk
9e167c5ed9 Initial commit 2013-08-17 00:15:57 -07:00