Giter Club home page Giter Club logo

asgineer's People

Contributors

almarklein avatar michaellenaghan avatar tlovely avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

asgineer's Issues

Common utilities

I intend to keep Asgish as simple as possible, but some tasks are common and can be abstracted as a utility. I am not sure whether I'd add any, but I might, e.g. when I find myself writing a certain piece of code in multiple places.

Examples:

  • Routing
  • Compression
  • Request caching headers

Rename handler2asgi?

I find that name rather ugly. Though it's explicit and clear...

Options:

  • Keep as is: clear but ugly
  • handler_to_asgi: possibly more ugly
  • application :/
  • make_asgi / to_asgi
  • ...

"304 Not Modified" is returning the wrong headers

There's a problem here:

if request_etag and request_etag == content_etag:

Take a look at this example:

$ curl -I -H "If-None-Match: 512dc2f89fea2c3794631fddb080e9db842542b0204cd3e2b13d1685d9f2a349" "http://localhost:5555/timetagger/"

HTTP/1.1 304 Not Modified
date: Wed, 28 Feb 2024 20:18:06 GMT
server: uvicorn
etag: 512dc2f89fea2c3794631fddb080e9db842542b0204cd3e2b13d1685d9f2a349
cache-control: public, must-revalidate, max-age=0
content-type: application/octet-stream
content-length: 0

Note the content-type (application/octet-stream) and content-length (0).

Now take a look at the description of "304 Not Modified" on MDN:

The response must not contain a body and must include the headers that would have been sent in an equivalent 200 OK response: Cache-Control, Content-Location, Date, ETag, Expires, and Vary.

This error is causing a problem when a server is proxied behind Apache. I can explain the problem, but it's complicated and I'm not sure getting into the details will help. The short version, more or less, is that Apache appears to notice the discrepancy, and substitutes a 404 response.

100% coverage

The new work in #11 would make it possible to see coverage, lets go for that 100%

Type hints

This would allow 3d party code that uses Asgish to hook up with Asgish better. And it is an extra validation step.

Websocket Authorization

I'd like to do authorization in a websocket handler before accepting the connection. For example:

async def websocket_handler(request):
    if not is_authorized(request):
        return 401, {"WWW-Authenticate": "Basic"}, "Invalid credentials"

    await request.accept()

I expected it to send the HTTP response, but instead it raised the following exception:

OSError: A websocket handler should return None; use request.send() and request.receive() to communicate.

Use of request.host

Should this return request.headers['host'] if available? That one is probably more what the user needs than request.context.server[0]

Can we do without a response class?

The point of Asgish is to be tiny. From the start it did not have a Response class like most other web frameworks. Here I write down some thought about that...

Any HTTP response is really just a status code, headers, and a body. And the first two can be set to sensible defaults in many cases. I like the idea of being able to write an Asgish handler in a module that has zero imports; this is what gives it this ASGI-ish feel ...

One use-case where a response object might be convenient is when the request is delegated to another handler, and you want to inspect/tweak its response. Though in such a situation you can mandate to internally use the three-tuple (status, headers, body) explicitly.

I'd be happy to hear if I am overlooking something.

Dont compress files that already are

make_asset_handler() compresses all files above a certain size, including e.g. .png. Instead, it should only use the compressed version if it's 90% or less of the original.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.