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

88 Commits

Author SHA1 Message Date
Joris Vink
f7678946a1 don't set our own exception on invalid parameters. 2018-04-11 13:32:56 +02:00
Joris Vink
4ab028633a If a python handler failed, don't fatal on purpose.
Instead log and send an internal error status back to the client.

This should be OK as long as the exception doesn't happen after
the caller called req.response() already.
2018-04-11 13:00:30 +02:00
Joris Vink
43a0aef29f prefix HTTP defines when exporting them to python. 2018-04-10 14:35:52 +02:00
Joris Vink
9c337ded1e Change kore_parent_configure() for single binaries.
This function now takes any remaining arguments passed on the command line
after kore parsed its own.

For C the new prototype looks like this:

void kore_parent_configure(int argc, char **argv);

For python code, kore will pass each argument to the function so you
can do things like:

def kore_parent_configure(arg1, arg2):
2018-04-09 12:51:20 +02:00
Joris Vink
ff21fd330f Add python_path configuration option.
Allows adding more items to the python path so imports from inside
python scripts work more sensible depending on how you configure your
app.
2018-03-01 12:55:33 +01: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
rouzier
f0f1296265 Add patch support (#217)
Add PATCH to supported verbs in config and what not.
2018-01-02 22:27:59 +01:00
Stanislav Yudin
b73343aea4 add HTTP_METHOD_OPTIONS as another supported http method. (#186) 2017-04-04 09:37:19 +02: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
add6d724e3 expose connection address to python. 2017-03-24 12:42:40 +01:00
Joris Vink
ffbabed7d6 Move websocket_send() to pyconnection.
While here convert all instances of y* for incoming binary data to y#
since we won't be changing it at all and avoids some unneeded copying.
2017-03-13 13:30:57 +01:00
Joris Vink
4a56424842 Improve python websocket handling a bit.
Convert the data parameter to a string if the op was WEBSOCKET_OP_TEXT
or convert to bytes if op was WEBSOCKET_OP_BINARY so the callee does
not have to do this anymore.
2017-03-13 12:29:42 +01:00
Joris Vink
0b84a9c1d4 expose c.disconnect() and c.fd to Python. 2017-03-13 12:22:50 +01:00
Joris Vink
af899f15e0 Set error if http_body_rewind() fails. 2017-03-13 11:19:58 +01:00
Joris Vink
ec901d0339 Make http_body_rewind() public.
Also let this function reset offset and lengths for http_body_read().

Make sure of this function in the python code so req.body can be called
multiple times in succession.
2017-03-13 11:17:55 +01:00
Joris Vink
c136c5ffc5 python_calloc() no longer needs manual memset. 2017-02-27 21:34:26 -08:00
Joris Vink
e89e644d10 call PyErr_Clear() before PyImport_ReloadModule(). 2017-02-22 20:54:57 +01:00
Joris Vink
c6ca68f3f2 export http_body_path via python 2017-02-22 17:52:57 +01: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
b8b8373702 when exiting clear any lingering python exceptions. 2017-02-06 16:54:38 +01:00
Joris Vink
ace8c4e80c Add asynchronous pgsql query support to python.
This commit adds the ability to use python "await" to suspend
execution of your page handler until the query sent to postgresql
has returned a result.

This is built upon the existing asynchrous query framework Kore had.

With this you can now write stuff like:

async def page(req):
	result = await req.pgsql("db", "SELECT name FROM table");
	req.response(200, json.dumps(result).encode("utf-8"))

The above code will fire off a query and suspend itself so Kore can
take care of business as usual until the query is successful at which
point Kore will jump back into the handler and resume.

This does not use threading, it's purely based on Python's excellent
coroutines and generators and Kore its built-in pgsql support.
2017-02-06 11:42:53 +01:00
Joris Vink
6578fc6589 expose http_file interface to python. 2017-02-01 21:23:56 +01:00
Joris Vink
3d8e0dabc0 expose kore_server_bind() and fatal() to python 2017-02-01 17:12:52 +01:00
Joris Vink
30666618f8 expose kore_websocket_send() to python. 2017-01-30 22:00:03 +01:00
Joris Vink
6bfba49ba5 cleanup data if required. 2017-01-30 21:50:36 +01:00
Joris Vink
f78e8f2fd2 allow None as source for kore.websocket_broadcast.
This allows kore.websocket_broadcast() to be used to relay the
messages back to all clients rather then all except the sender.
2017-01-30 21:48:58 +01:00
Joris Vink
6a43dd529c export WEBSOCKET_OP_TEXT and WEBSOCKET_OP_BINARY. 2017-01-30 21:02:58 +01:00
Joris Vink
7bc8bb42e2 implement kore_websockat_broadcast. 2017-01-30 20:30:42 +01:00
Joris Vink
7510834968 initial fudging to add websockets to python 2017-01-29 22:57:34 +01:00
Joris Vink
c06ecf1c70 Teach single binaries about SIGHUP.
Make sure kore_onload() and kore_preload() can be called
either in native or python runtime.
2017-01-26 13:26:55 +01:00
Joris Vink
dcb5fd842f Expose get/post params via req.argument for python. 2017-01-26 12:01:28 +01:00
Joris Vink
1db3cd96d8 allow reloading of python modules on SIGHUP. 2017-01-26 11:13:09 +01:00
Joris Vink
21f9c29f31 style + move pyhttp_dealloc() into !KORE_NO_HTTP. 2017-01-25 22:33:39 +01:00
Joris Vink
9976022a47 let python use kore backed memory allocators. 2017-01-25 22:07:58 +01:00
Joris Vink
620cc231dc validators now work in python. 2017-01-25 21:17:12 +01:00
Joris Vink
7c74a0824b push all integers exported to python in a struct. 2017-01-25 20:56:57 +01:00
Joris Vink
bbcdec82fc Add initial python support.
Based on work done by Stanislav Yudin.
2017-01-24 20:18:12 +01:00