Commit Graph

1039 Commits

Author SHA1 Message Date
Joris Vink 89e58fa474 Improve iterator support for Python req.response().
If the connection on which we are about to send the response was
marked as disconnecting, do not go ahead and hook into the disconnect
callback (it will never be called, it is already disconnecting).

Instead just return, the connection will be removed anyway.
2019-06-05 10:35:47 +02:00
Joris Vink 93b1d621d7 Remove memleak from Python httpclient.
We grab a reference to the pyhttp_client for the client_op data structure
but never removed it. This caused the pyhttp_client object to never
be released when out of scope.
2019-06-05 10:27:20 +02:00
Joris Vink a4d18ca276 Add HTTP runlocks.
A way to serialize access to HTTP page handlers in case you are
using some asynchronous api such as pgsql or libcurl stuff.
2019-06-02 16:29:54 +02:00
Joris Vink 1686ec22e6 Some C pgsql api improvements. 2019-06-01 23:14:50 +02:00
Joris Vink ff7c85460c Wake up HTTP requests if python coros finish immediately.
python_coro_create() puts the HTTP request to sleep, but if they
finish immediately they will be removed from the list and should
properly be woken up or they are removed from the wrong list.
2019-05-30 17:15:08 +02:00
Joris Vink a8aff8b737 Improve curl error string handling.
Introduce kore_curl_strerror(), use this in kore_curl_logerror()
instead of assuming our errbuf has been populated.

Also use it in the python httpclient when throwing an exception rather
then looking at the errbuf member which may or may not be empty.
2019-05-30 14:25:04 +02:00
Joris Vink 88553cd2dd Immediately remove completed HTTP requests.
No need to wait until the next time http_process() is called, which
could result in HTTP requests backing up even though we are processing
them at a fast pace.
2019-05-29 20:30:43 +02:00
Joris Vink 07fc7a9097 Improve HTTP processing.
If netwait is INFINITE but there are requests pending reduce the
netwait back down to 100ms so we keep processing them.
2019-05-29 15:27:44 +02:00
Joris Vink c2d9f1413c Fix two concurrency issues with kore.lock().
1) If a coroutine was waken up by another releasing a lock it was waiting
on we would incorrectly remove the pylock_op when the newly awoken coroutine
hits the iternext for pylock.

2) If a coroutine attempts to grab a lock it was woken up for only to fail
we did not properly rearm the coroutine to be woken up later to try again.
2019-05-29 15:25:31 +02:00
Joris Vink 5f0153ba0e Fix unix binds on BSD families. 2019-05-28 21:44:46 +02:00
Joris Vink b4aba48fad small python improvements.
- Check for an exception when in a timer context and log it if uncaught.
- Make sure tlsverify is settable regardless of client certs being specified.
2019-05-16 21:07:42 +02:00
Joris Vink a10dfe03fe make sure user-defined headers are set for > 500.
a commit done in 2018 prevented http responses with error codes
> 500 to include any user-set headers, preventing a developer
to include things like content-type etc.

reported by Arun Babu via users@
2019-05-12 20:53:27 +02:00
Joris Vink 53f042a5b4 add stdint.h header to keymgr.c 2019-05-09 20:55:49 +02:00
Joris Vink 3299f60df4 tiny curl fixes. 2019-05-05 21:16:42 +02:00
Joris Vink 503f42074c http_timeout must be 0 when upgrading to websockets
otherwise kore will timeout an established websocket connection
after http_timeout seconds.
2019-05-05 14:47:04 +02:00
Joris Vink fe84997ce9 add option to use unix paths via kore.httpclient 2019-05-03 15:31:16 +02:00
Joris Vink 3c9a141cd0 allow an iterator to be passed to req.response().
if an iterator is passed kore will send the response with
transfer-encoding: chunked and call the iterator for every
chunk that was sent.

The iterator must return a utf-8 string.

Works wonderful with TemplateStream from jinja2.
2019-05-03 13:42:34 +02:00
Joris Vink 12fc1396c1 use / to split up name/version. 2019-04-30 20:45:56 +02:00
Joris Vink 502368a27e set user-agent in the curl component. 2019-04-30 20:39:46 +02:00
Joris Vink 403938d8e9 make native proctitle better.
count how much space is available for a mangled process title
only once, and use that as reference later.
2019-04-29 21:08:58 +02:00
Joris Vink d0a6958747 Let http_state_create() take an "onfree" callback.
This function is called when an HTTP request is being free'd,
allowing you to perform any sort of state cleanup attached
to the HTTP request.
2019-04-28 21:48:16 +02:00
Joris Vink 9ac77d0c9a make sure CURL_CSELECT_ERR is OR'd into flags. 2019-04-28 21:44:59 +02:00
Joris Vink e54886960e objs is a pointer, and use Py_XDECREF on it. 2019-04-25 23:25:19 +02:00
Joris Vink d0d0bdeb4f Improve pgsql support.
- Add kore_pgsql_query_param_fields() which allows you to pass in the
  arrays for values, lengths and formats yourself.

- Add kore_pgsql_column_binary() which will return 1 if the given column
  index contains a binary result or 0 if it contains a text result.

- Change the query call in req.pgsql() for Python to always use the
  parameterized queries.

This adds the 'params' and 'binary' keywords to the req.pgsql method.

Eg:
	result = await req.pgsql("db", "INSERT INTO foo (field) VALUES($1"),
	    params=["this is my value"])
2019-04-25 23:13:13 +02:00
Joris Vink 994f428a8d add cabundle keyword to kore.httpclient() 2019-04-24 21:09:24 +02:00
Joris Vink 6bd3d92fe2 unbreak. 2019-04-24 18:30:07 +02:00
Joris Vink a6af458cd2 add tlsverify keyword to kore.httpclient(). 2019-04-24 18:28:23 +02:00
Joris Vink 1b9ba84ab0 missing return value check. 2019-04-24 09:33:56 +02:00
Joris Vink a9683caed5 missing header 2019-04-24 00:16:51 +02:00
Joris Vink 2c88bc6120 Add asynchronous libcurl support.
This commit adds the CURL=1 build option. When enabled allows
you to schedule CURL easy handles onto the Kore event loop.

It also adds an easy to use HTTP client API that abstracts away the
settings required from libcurl to make HTTP requests.

Tied together with HTTP request state machines this means you can
write fully asynchronous HTTP client requests in an easy way.

Additionally this exposes that API to the Python code as well
allowing you do to things like:

	client = kore.httpclient("https://kore.io")
	status, body = await client.get()

Introduces 2 configuration options:
	- curl_recv_max
		Max incoming bytes for a response.

	- curl_timeout
		Timeout in seconds before a transfer is cancelled.

This API also allows you to take the CURL easy handle and send emails
with it, run FTP, etc. All asynchronously.
2019-04-24 00:15:17 +02:00
Joris Vink c89ba3daa3 check http timeouts better 2019-04-12 14:26:47 +02:00
Joris Vink 612fc034fa remove debug 2019-04-11 20:54:29 +02:00
Joris Vink aa49e181b6 Add http_[header|body]_timeout.
If the HTTP request headers or the HTTP body have not arrived before
these timeouts expire, Kore will send a 408 back to the client.
2019-04-11 20:51:49 +02:00
Joris Vink a191445f76 set body length+offset to 0 when populating data.
otherwise this isn't properly picked up by http_body_read() later
if dealing with in-memory HTTP bodies and you get inconsistent behaviour.
2019-04-02 22:26:44 +02:00
Joris Vink 5d16a7a123 make sure stdint.h is always included.
unbreaks NOTLS=1 and NOSENDFILE=1 builds on several platforms.

reported by Sam on irc, thanks.
2019-03-29 19:25:27 +01:00
Joris Vink a66d259271 kill debug line 2019-03-29 19:15:10 +01:00
Joris Vink d2aa64df5c add kore_proctitle().
manipulates the argv+environ pointers to get a sensible process title
under linux / darwin.
2019-03-29 16:24:14 +01:00
Joris Vink 92fb4974b1 only deschedule if not -1. 2019-03-27 22:15:35 +01:00
Joris Vink 39ffa047ca remove dh parameter check at configure time.
this is done when the workers startup if a domain with tls was used.
2019-03-26 21:44:44 +01:00
Joris Vink e4caac9e0c Be more clear when an invalid TLS setup is found 2019-03-26 21:36:45 +01:00
Joris Vink bf42e56c7d kill whitespace 2019-03-26 20:24:46 +01:00
Joris Vink 4ca7f29649 Add a concurrency parameter to kore.gather() 2019-03-25 10:13:52 +01:00
Joris Vink e1766e74ba always capture worker processes exiting.
even if they terminated normally.
2019-03-22 10:29:14 +01:00
Joris Vink 4238431b9e Add worker_death_policy setting.
By default kore will restart worker processes if they terminate
unexpected. However in certain scenarios you may want to bring down
an entire kore instance if a worker process fails.

By setting worker_death_policy to "terminate" the Kore server will
completely stop if a worker exits unexpected.
2019-03-22 09:49:50 +01:00
Joris Vink cd80685d9d get rid of pyko 2019-03-21 21:37:16 +01:00
Joris Vink 58c2739dee If fd is -1 in pysock_op_iternext just return None.
None in pysock signals EOF and if it was closed under our feet we should
relay that properly.
2019-03-21 14:44:41 +01:00
Joris Vink 370041656e Get rid of WORKER_LOCK_TIMEOUT.
Instead let the workers send a message on the msg channel to each
other when they have given up the accept lock and it is now available
to be grabbed.
2019-03-21 14:03:11 +01:00
Joris Vink 8b0279879a rework timers so they fire more predictably.
this change also stops python coroutines from waking up very
late after their timeout has expired.

in filerefs, don't prime the timer until we actually have something
to expire, and kill the timer when the last ref drops.
2019-03-21 10:17:08 +01:00
Joris Vink ce012e7bd5 set fd to -1 on close. 2019-03-21 10:09:24 +01:00
Joris Vink d371454dad do not grab the result if it was in a gatherop 2019-03-19 13:58:00 +01:00