semvec/pypi-packages huggingface dataset:
thruster 0.0.8
ASGI compatible HTTP/2 web server

# Thruster
HTTP/2 Server that just works

This is my attempt at writing a fully functional HTTP 2.0 Server in Python. Its a work in progress right now.
The server supports the ASGI 1.0 specification. Has no dependency on the hyper/h2 (except hpack) and twisted packages.
The HTTP/2 stack is being implemented completely from scratch.
Depends on [bitstring](https://pythonhosted.org/bitstring/) for handling binary data for the HTTP/2 protocol implementation.

## HTTP/2 (Current Status)
- Implementation of most HTTP/2 frames is done. Implemenation of rest of the frames will be done as use cases arise.
- All frames are organized in classes, with the Frame class as the parent.
- ASGI 1.0 is supported. Will be adding support for 2.0 soon.
- Flow Control (To be added)
- Stream prioritization (To be added)
- Works with Django (Tested against Django 1.11 and 2.2)

## Usage
Install the package using pip
- pip3 install thruster

Run the following command:
- thruster --app path_to_your_asgi_app --cert-file path_to_certificate_file --key-file path_to_key_file
- eg: thruster --app mysite --cert-file server_cert.crt --key-file server_key.key

--cert-file is expected to be a .crt file and --key-file is expected to be a .key file. If --cert-file and --key-file options are not passed, thruster will look for server.crt and server.key in the current directory.
--cert-file and --key-file are required for SSL connections and HTTP2 only works with SSL. You can use --help to know about for more options.
If everything goes fine you should see the following output on the terminal.

Serving HTTP on port 8000 ...

The structure of your ASGI application is expected to be something like this. Eg: If you're using django.

root_directory/
	asgi.py
	routing.py
	settings.py

asgi.py

```python
import os
import django
from channels.routing import get_default_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "mysite.settings")
django.setup()
application = get_default_application()
```

routing.py
```python
from channels.routing import ProtocolTypeRouter

application = ProtocolTypeRouter({})
```

settings.py
```python
ASGI_APPLICATION = 'mysite.routing.application'
```
accept-types 0.4.1
Determine the best content to send in an HTTP response

========================================================
accept-types - Use the correct accept type for a request
========================================================

``accept-types`` helps your application respond to a HTTP request in a way that a client prefers.
The ``Accept`` header of an HTTP request informs the server which MIME types the client is expecting
back from this request, with weighting to indicate the most prefered. If your server can respond in
multiple formats (e.g.: JSON, XML, HTML), the client can easily tell your server which is the
prefered format without resorting to hacks like '&amp;format=json' on the end of query strings.


Usage
=====

``get_best_match``
------------------

When provided with an ``Accept`` header and a list of types your server can respond with, this function
returns the clients most prefered type. This function will only return one of the acceptable types you
passed in, or ``None`` if no suitable type was found:

.. code:: python

	from accept_type import get_best_match

	def get_the_info(request):
		info = gather_info()

		return_type = get_best_match(request.META.get('HTTP_ACCEPT'), ['text/html', 'application/xml', 'text/json'])

		if return_type == 'application/xml':
			return render_xml(info)

		elif return_type == 'text/json':
			return render_json(info)

		elif return_type == 'text/html':
			return render_html(info)

		elif return_type == None:
			return HttpResponse406()

``parse_header``
----------------

When provided with an ``Accept`` header, this will parse it and return a sorted list of the clients
accepted mime types. These will be instances of the ``AcceptableType`` class.

.. code:: python

	>>> from accept_type import parse_header
	>>> parse_header('text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')
	['text/html, weight 1', 'application/xhtml+xml, weight 1', 'application/xml, weight 0.9', '*/*, weight 0.8']

``AcceptableType``
------------------

``AcceptableType`` instances represent one of the types that a client is willing to accept. This
type could include wildcards, to match more than one MIME type.

.. code:: python

	>>> from accept_type import AcceptableType
	>>> type = AcceptableType('image/*;q=0.9')
	AcceptableType
	>>> type.mime_type
	'image/*'
	>>> type.weight
	0.9
	>>> type.matches('image/png')
	True
	>>> type.matches('text/html')
	False