Commit Graph

160 Commits

Author SHA1 Message Date
Joris Vink a20fb00789 req can be NULL if we are coming from an error path. 2015-08-02 16:53:40 +02:00
Joris Vink be3fa17201 Do not send connection:close for websocket upgrades. 2015-06-30 16:43:21 +02:00
Cleve Lendon 18becccd5a Fix indentation. 2015-06-30 18:07:45 +09:00
Cleve Lendon fef3ee8efe Fix websockets. Connection must be Upgrade, not keep-alive, Upgrade 2015-06-26 12:14:01 +09:00
Joris Vink a97e18bbe9 Shuffle some HTTP_REQUEST_NO_CONTENT_LENGTH around 2015-05-19 09:13:29 +02:00
Joris Vink e33710b26a Wrap expression with some additional parenthesis. 2015-05-19 09:04:46 +02:00
Quentin Perez ff4faa98b7 fix-null-dereference
http.c:1214, req->method
http.c:1272, req->flags
2015-05-18 23:42:50 +02:00
Joris Vink 1dd7407a41 Close SPDY streams if len == 0 and SPDY_NO_CLOSE is not set. 2015-05-15 19:16:35 +02:00
Joris Vink cefeaf7992 HTTP layer improvements.
Add HTTP_REQUEST_NO_CONTENT_LENGTH which can be set by
a handler before calling http_response() to avoid Kore
from setting the content-length altogether.

If we are on a SPDY connection do not close the stream
if we do not pass data to http_response().
2015-05-15 19:12:18 +02:00
Joris Vink 09ed61187b Unfuck content-length changes.
We want a content-length unless its 204 or status < 200.
2015-05-13 09:16:06 +02:00
Joris Vink 7ce742f131 Merge pull request #48 from thorduri/content-length
Always write out content-length;
2015-05-13 09:02:58 +02:00
Thordur Bjornsson a62bce3e88 Always write out content-length;
Unless status is 204 or 1xx (informational).
2015-05-12 20:23:47 +02:00
Joris Vink 4f36b534aa Reset fsm_state back to 0 after we're done with it. 2015-05-08 21:19:20 +02:00
Joris Vink e5f6d37cd2 Make parameter validation less noisy. 2015-04-27 15:35:02 +02:00
Joris Vink dc6e6fb1b4 Kill NETBUF_CALL_CB_ALWAYS for incoming HTTP body
Do not let the NETBUF_CALL_CB_ALWAYS flag linger in
the netbuf we reset for the incoming HTTP body.
2015-04-21 11:30:59 +02:00
Joris Vink dfea3cf483 Place path and host in http_request into pools.
Also change the amount of times we end of doing unneccessairy strlen() calls.
2015-04-15 12:40:15 +02:00
Joris Vink 097a1166df Improve very heavy load handling.
Introduces two new configuration knobs:
	* socket_backlog (backlog for listen(2))
	* http_request_limit

The second one is the most interesting one.

Before, kore would iterate over all received HTTP requests
in its queue before returning out of http_process().

Under heavy load this queue can cause Kore to spend a considerable
amount of time iterating over said queue. With the http_request_limit,
kore will process at MOST http_request_limit requests before returning
back to the event loop.

This means responses to processed requests are sent out much quicker
and allows kore to handle any other incoming requests more gracefully.
2015-04-09 15:29:44 +02:00
Joris Vink af865abede Bump copyright to 2015 2015-04-07 13:08:26 +02:00
Joris Vink cf028f20b6 Rename kore_auth() to kore_auth_run(). 2015-04-02 13:45:42 +02:00
Joris Vink b234b7ed65 Add HTTP_REQUEST_RETAIN_EXTRA flag to http_request
Signals Kore to not free any pointer set in req->hdlr_extra.
Useful in certain scenarios where you have data per request
bound to something in memory but do not want to lose it when
the request is freed by Kore.

Set this flag before your handler returns.
2015-03-27 23:23:21 +01:00
Joris Vink ad5d662556 Use net_recv_reset() if more body bytes are coming.
Unbreaks clients that send the headers first and the
actual HTTP body after X amount of time.
2015-03-16 16:45:13 +01:00
Joris Vink 91c44af6f0 Always include includeSubDomains for HSTS. 2015-02-10 17:14:07 +01:00
Joris Vink 1507f88ec7 Respect keepalive when throwing HTTP errors.
Report from github issue #34
2015-02-06 10:59:15 +01:00
Joris Vink dbe301e58c Add a patch level to our version number. 2014-12-12 13:06:41 +01:00
Joris Vink f867882f43 Add websocket support to Kore.
Introduces a few new api functions:

- kore_websocket_handshake(struct http_request *):
	Performs the handshake on an HTTP request (coming from page handler)

- kore_websocket_send(struct connection *, u_int8_t, void *, size_t):
	Sends data to a websocket connection.

- kore_websocket_broadcast(struct connection *, u_int8_t, void *, size_t, int):
	Broadcast the given websocket op and data to all connected
	websocket clients on the worker. Note that as of right now
	the WEBSOCKET_BROADCAST_GLOBAL scope option does not work
	yet and messages broadcasted will be restricted to workers
	only.

- kore_worker_websocket_broadcast(struct connection *, void *, void *):
	Backend function used by kore_websocket_broadcast().
	Could prove useful for developers to have access to.

A simple example is given under examples/websocket.

Known issues:
	Kore does not support PING or CONT frames just yet.
2014-11-24 11:08:34 +01:00
Joris Vink 6de0f8568a Rework net, worker and some http internals.
- The net code no longer has a recv_queue, instead reuse same recv buffer.
- Introduce net_recv_reset() to reset the recv buffer when needed.
- Have the workers spread the load better between them by slightly
  delaying their next accept lock and giving them an accept treshold
  so they don't go ahead and keep accepting connections if they end
  up winning the race constantly between the workers.
- The kore_worker_acceptlock_release() is no longer available.

- Prepopulate the HTTP server response header that is added to each
  response in both normal HTTP and SPDY modes.
- The path and host members of http_request are now allocated on the heap.

These changes overall result better performance on a multicore machine,
especially the worker load changes shine through.
2014-10-22 21:16:49 +02:00
Joris Vink a603b77e24 Add PUT/DELETE/HEAD methods (finally).
This commit renames certain POST centric variable and configuration
naming to the correct HTTP body stuff.

API changes include http_postbody_text() and http_postbody_bytes() to
have become http_body_text() and http_body_bytes().

The developer is still responsible for validating the method their
page handler is called with. Hopefully this becomes a configuration
option soon enough.
2014-10-08 11:03:14 +02:00
Joris Vink c0c3e9fb05 Use s instead of req->stream. 2014-09-19 15:01:25 +02:00
Joris Vink f3e863a482 Properly end headers when doing status codes only. 2014-08-25 10:58:34 +02:00
Joris Vink 0542d70a71 Use a single header_buf in http_response_normal()
Avoids constantly allocating and freeing buffers all the time.
This can be done safely due to the fact workers are single threaded.
2014-08-22 14:38:48 +02:00
Joris Vink 7e74cd6e62 Introduce a wait queue for our pgsql code.
Instead of letting http_requests spin, if we cannot allocate
a connection for the request we will queue them up put them to sleep.

When a connection becomes available, we'll wake up a request that
was waiting for a connection and let it continue.

This completely avoids consuming massive amounts of cpu time
when dealing with thousands of requests waiting for a pgsql
worker to become ready.
2014-08-21 16:36:12 +02:00
Joris Vink d3149a2a71 We need at most 2 tokens here 2014-08-18 21:13:16 +02:00
Joris Vink 105804e325 Make http_status_text() return a const char 2014-08-18 10:37:13 +02:00
Joris Vink 873c68b515 Make http_status_text() available everywhere 2014-08-18 10:34:47 +02:00
Joris Vink 8565b47800 Attach tasks/pgsqls to http_requests once more.
This way if an http request is removed while tasks or
pgsqls are still active they are free'd out and cancelled
properly.
2014-08-14 22:05:34 +02:00
Joris Vink f93747828c Major pgsql rework.
Gone is the ugly KORE_PGSQL macro that hid an overly complex
state machine for the pgsql api.
Gone is the pgsql array that was attached to http_requests.
Gone are the callback hacks inside the pgsql api.

Instead, I strongly encourage people to use the new state machine
api Kore offers to properly deal with asynchronous queries.

The pgsql example in examples/pgsql has been updated to reflect
these changes.
2014-08-14 14:34:23 +02:00
Joris Vink 856d7b0cb2 Rename HTTP_STATE_OK to HTTP_STATE_CONTINUE 2014-08-14 11:20:04 +02:00
Joris Vink 210fb05a35 Add a hopefully easy to use and optional fsm for page handlers
In order to use this, define states for your page handler:

struct http_state mystates[] = {
	{ "PAGE_STATE_INIT",	page_init },
	{ "PAGE_STATE_RESULT",	page_result },
};

In your page handler you can then simply call http_state_run() with
your states and http_request. This will cause Kore to start calling
your state callbacks beginning at index 0.

State callbacks have the same prototype as page handlers:

int	func(struct http_request *);

However, unlike page handlers they MUST return one of the following:

- HTTP_STATE_OK:	All good, just continue the fsm.
- HTTP_STATE_ERROR:	Abort fsm and return KORE_RESULT_OK to Kore
			(This will cancel the http request).
- HTTP_STATE_RETRY:	Return KORE_RESULT_RETRY to Kore.
			(Kore will retry your page handler next event loop).
- HTTP_STATE_COMPLETE:	The fsm completed, break out cleanly.

Note that using this is completely optional and you can still
use the traditional way of writing page handlers.

The fsm is designed to get rid of the clutter that exists today
in Kore when dealing with non blocking tasks or pgsql calls.
2014-08-13 23:34:30 +02:00
Joris Vink 29afdd0b21 Make sure opt always contains what we want 2014-08-13 14:32:49 +02:00
Joris Vink 97c17f724b Add kore_snprintf() as a wrapper around snprintf(). 2014-08-11 10:45:10 +02:00
Joris Vink c665b7d926 Add a callback to http_response_stream().
This way we can get our code called whenever a stream is
completed. This cb handler does stand alone from an http_request
and is passed a netbuf data structure.
2014-08-10 18:46:44 +02:00
Joris Vink 10284d59b6 Another round of spdy/3.1 improvements.
* Always make sure we end the stream properly
* Check for SPDY_FLOW_WINDOW_MAX on window frame updates
* Kill SPDY_STREAM_BLOCKING, once flow control kicks in its per session
2014-08-10 18:18:27 +02:00
Joris Vink 5cca2f1f78 properly implement spdy/3.1 flow control 2014-08-08 14:18:15 +02:00
Joris Vink d2c65b4f62 Change http_response_stream() to only take a base + len 2014-08-07 14:31:45 +02:00
Joris Vink cda09b6065 Add http_response_stream() which can stream data from a buffer to the client. 2014-08-07 14:23:26 +02:00
Joris Vink 966ed3d20d Rename the two functions used to read/set headers.
Rename http_request_header_get() to http_request_header().
Rename http_response_header_add() to http_response_header().
2014-08-05 14:26:31 +02:00
Joris Vink 0413de6a8f fatal if the return value from a page handler isn't what we want. 2014-08-05 14:17:23 +02:00
Joris Vink b0700162c4 Make http_post_data_bytes() and http_post_data_text() available 2014-08-04 21:03:26 +02:00
Joris Vink 9b3ff7db53 Lowercase the HTTP headers sent in normal HTTP responses.
SPDY already had this, as required by the spec.
2014-08-04 20:12:31 +02:00
Joris Vink 31eac77cd2 sprinkle const char where appropriate 2014-08-04 09:48:41 +02:00