1
0
mirror of https://git.kore.io/kore.git synced 2024-11-19 00:17:08 +01:00
Commit Graph

142 Commits

Author SHA1 Message Date
Joris Vink
3dfad1b7d6 remove unneeded include. 2018-05-04 15:56:56 +02:00
Joris Vink
439a3b36f0 Add kore_strtodouble().
Use it for http_argument_get_float() and http_argument_get_double().
2018-05-04 15:55:35 +02:00
Joris Vink
b7669f49f7 typo 2018-05-03 21:40:50 +02:00
Joris Vink
43a0aef29f prefix HTTP defines when exporting them to python. 2018-04-10 14:35:52 +02:00
Joris Vink
dd2dff2318 Rework HTTP and worker processes.
The HTTP layer used to make a copy of each incoming header and its
value for a request. Stop doing that and make HTTP headers zero-copy
all across the board.

This change comes with some api function changes, notably the
http_request_header() function which now takes a const char ** rather
than a char ** out pointer.

This commit also constifies several members of http_request, beware.

Additional rework how the worker processes deal with the accept lock.

Before:
	if a worker held the accept lock and it accepted a new connection
	it would release the lock for others and back off for 500ms before
	attempting to grab the lock again.

	This approach worked but under high load this starts becoming obvious.

Now:
	- workers not holding the accept lock and not having any connections
	  will wait less long before returning from kore_platform_event_wait().

	- workers not holding the accept lock will no longer blindly wait
	  an arbitrary amount in kore_platform_event_wait() but will look
	  at how long until the next lock grab is and base their timeout
	  on that.

	- if a worker its next_lock timeout is up and failed to grab the
	  lock it will try again in half the time again.

	- the worker process holding the lock will when releasing the lock
	  double check if it still has space for newer connections, if it does
	  it will keep the lock until it is full. This prevents the lock from
	  bouncing between several non busy worker processes all the time.

Additional fixes:

- Reduce the number of times we check the timeout list, only do it twice
  per second rather then every event tick.
- Fix solo worker count for TLS (we actually hold two processes, not one).
- Make sure we don't accidentally miscalculate the idle time causing new
  connections under heavy load to instantly drop.
- Swap from gettimeofday() to clock_gettime() now that MacOS caught up.
2018-02-14 13:48:49 +01:00
Joris Vink
548348f553 2018 2018-01-20 22:51:06 +01:00
Joris Vink
b95b623e72 Allow param blocks to be marked as "querystring"
Before params get would mean querystring and anything else
would just count toward a www-encoded body.

Now you can prefix the params block with "qs" indicating that
those configured parameters are allowed to occur in the query
string regardless of the method used.

This means you can do something like:

params qs:post /uri {
	...
}

to specify what the allowed parameters are in the querystring for
a POST request towards /uri.

inspired by and properly fixes #205.
2018-01-16 18:47:50 +01:00
Joris Vink
fcc044af87 change all domain directives to * in examples. 2017-09-19 15:16:02 +02:00
Joris Vink
92b4225814 add memory tag example 2017-08-30 11:50:02 +02:00
bhesmans
a2d78179a4 Small fix in video stream example (#195) 2017-06-25 11:46:32 +02:00
Joris Vink
19b7f75b90 change up a comment that is wrong. 2017-06-01 10:10:54 +02:00
Joris Vink
a3ed3bf7eb Convert pgsql-sync example after pgsql changes.
Only check if we bound something if we're asynchronous.
2017-03-24 13:00:05 +01:00
Joris Vink
59f7e85f45 Decouple pgsql from the http layer.
When the pgsql layer was introduced it was tightly coupled with the
http layer in order to make async work fluently.

The time has come to split these up and follow the same method we
used for tasks, allowing either http requests to be tied to a pgsql
data structure or a simple callback function.

This also reworks the internal queueing of pgsql requests until
connections to the db are available again.

The following API functions were changes:
	- kore_pgsql_query_init() -> kore_pgsql_setup()
		no longer takes an http_request parameter.
	- NEW kore_pgsql_init()
		must be called before operating on an kore_pgsql structure.
	- NEW kore_pgsql_bind_request()
		binds an http_request to a kore_pgsql data structure.
	- NEW kore_pgsql_bind_callback()
		binds a callback to a kore_pgsql data structure.

With all of this you can now build kore with PGSQL=1 NOHTTP=1.

The pgsql/ example has been updated to reflect these changes and
new features.
2017-03-24 12:53:07 +01:00
Joris Vink
3b5d4a2b03 update example 2017-03-13 13:31:36 +01:00
Joris Vink
3ae9bb7ae9 change type of maxage. 2017-03-10 14:36:51 +01:00
Joris Vink
4db51d7846 screw it, rework interface for cookies.
The only reason you would want to directly modify the cookie
after creating it should be to unset the HTTPONLY or SECURE flags
if that is what you *really* want to do.

Change http_response_cookie() to take all required parameters instead
of having to marshall those in yourself after.

Now you set a sane default cookie in one shot:

http_response_cookie(req, "key", "value", "/", 0, -1, NULL);

Which would create a session cookie key=value for / under the current domain.
2017-03-10 14:31:08 +01:00
Joris Vink
3d24b65268 Change default http_cookie behaviour.
We now default to httponly & secure for newly created cookies.

This should've been the default all along.

The http_response_cookie() no longer returns a pointer to http_cookie
but rather takes it as a parameter and will populate the pointer with
the newly created http_cookie if not NULL.

Additionally http_response_cookie() automatically sets the domain
based on the http_request passed into the function.
2017-03-10 14:20:40 +01:00
Joris Vink
edd7a10773 move static assets to use asset_serve_* in generic.
note that certain browsers change their caching behaviour when you
are connecting over TLS using self-signed certificates.

reminded by #179
2017-03-08 10:20:53 +01:00
Joris Vink
175b2e2c9b kore flavor -> kodev flavor 2017-03-06 23:18:16 +01:00
Joris Vink
f1d33ab91b kore -> kodev where appropriate 2017-03-06 11:00:53 +01:00
Joris Vink
3e84502235 Adjust examples after recent changes.
- New kodev tool generates config with server.pem/key.pem.
- Use proper formats for kore_log().
- Update to new websocket api.
2017-02-25 17:02:39 -08:00
Joris Vink
e9b4f966c2 expose new cookie stuff to python.
req.populate_cookies()
value = req.cookie("name")
2017-02-07 22:54:42 +01:00
Joris Vink
7c78dea211 more cookie example improvements.
- remove unneed headers.
- rename local to avoid shadowing.
2017-02-07 22:12:56 +01:00
Joris Vink
4e556dbd8f rename example cookies source file. 2017-02-07 22:06:31 +01:00
Joris Vink
36e99072f3 cookie example improvements. 2017-02-07 22:04:00 +01:00
Stanislav Yudin
f4ac8c2955 Cookies and arguments parsing improvements (#166)
Add new cookie API for handling of cookies.
2017-02-07 21:49:10 +01:00
Joris Vink
21bf7f9583 rework base example a bit. 2017-02-06 12:21:40 +01:00
Joris Vink
9f3046bae7 add README 2017-02-06 11:52:24 +01:00
Joris Vink
0bf36b763a add new python-pgsql example 2017-02-06 11:51:49 +01:00
Joris Vink
d3f84db4b8 small fixes. 2017-02-01 21:36:53 +01:00
Joris Vink
7fb47da586 add http_file example to python example. 2017-02-01 21:35:44 +01:00
Joris Vink
261fb3c3fa flesh out python example a bit more. 2017-02-01 17:15:18 +01:00
Joris Vink
8629419253 the example uses tls by default, so use it. 2017-01-31 09:21:06 +01:00
Joris Vink
6e7de9ab93 update python ws example. 2017-01-30 22:40:59 +01:00
Joris Vink
3d3d705b98 flesh out the python stuff a bit more. 2017-01-30 20:47:24 +01:00
Joris Vink
7bc8bb42e2 implement kore_websockat_broadcast. 2017-01-30 20:30:42 +01:00
Joris Vink
5485967547 add websocket example to python 2017-01-29 22:57:55 +01:00
Joris Vink
7510834968 initial fudging to add websockets to python 2017-01-29 22:57:34 +01:00
Joris Vink
829066dc23 i can't port. 2017-01-26 22:02:11 +01:00
Joris Vink
4940f97079 remove stuff that is not ready yet and add README. 2017-01-26 22:01:23 +01:00
Joris Vink
ef441fb9a1 bah, be gone. 2017-01-25 22:38:43 +01:00
Joris Vink
ff48aed926 initial python example.
don't look too much into this yet.
2017-01-25 22:38:06 +01:00
Yorick de Wid
86d85dd10b Message shutdown request (#168)
* Set server version

* Message shutdown request

* Update messaging example

* Set server verion in generic example

* Allow shutdown with NOHTTP=1
2017-01-17 18:18:01 +01:00
john721
f15558ed98 Fix no response in case kore was built with NOTLS=1. (#142) 2016-08-16 10:19:07 +02:00
Raphaël Monrouzeau
32ac27d4c3 JSONRPC Reverted explicit deallocation calls
The possibility to call jsonrpc_destroy_request was left. Someone may
want to abruptly interrupt the process of its request for some odd
reason, in that case an exlicit call still would be to be made.
2016-07-15 13:08:08 +02:00
Raphaël Monrouzeau
016dc27346 JSONRPC Made request destruction explicit
Caller has now to destroy jsonrpc_request after use. This permits them
to read / inspect it after having responded.
2016-07-15 13:08:08 +02:00
Raphaël Monrouzeau
8c78b28be3 JSONRPC Removed upload size limit check
A true application dependant limit check would require stream parsing.
As the limit enforcement was done, it added nothing of value compared
to HTTP request limit check, which is in Kore already.
2016-07-15 13:08:08 +02:00
Raphaël Monrouzeau
3366ec6573 Required params to be structured as per spec 2016-07-15 13:08:08 +02:00
Raphaël Monrouzeau
4ffe43cf87 Compliantly don't return anything to notifications
And don't return anything either if protocol doesn't match.
2016-07-15 13:08:08 +02:00
Raphaël Monrouzeau
db02e990ea JSON-RPC support for Kore.
The API surface is very limited. Jsonrpc support reads request from HTTP
body and such can't be activated if NOHTTP=1. At the moment there is no
websocket support either (which is a shame). It depends upon the
third-party Yajl library.

Errors can be emitted using jsonrpc_error() and results using
jsonrpc_result(), for the later you'll have to provide a callback which
will write the inner of the result object.

If errors happen during the response write process, no further error
output will be attempted and an HTTP error 500 will be returned.

Read the provided example for getting a better idea of the API.
2016-07-15 13:08:08 +02:00