Code Monkey home page Code Monkey logo

Comments (8)

thomasp85 avatar thomasp85 commented on May 17, 2024

Great to hear that you are working on a plugin!

The most basic answer to your question is: Add the event handler to the header event. This event will be triggered once all headers have been recieved but before the body gets loaded, so it's a natural place to put this sort of behaviour. The semantics is that if the last handler returns FALSE the response is send back without being processed in the request loop. Take a look at the size_limit route in routr for a possible approach to cutting of processing (this time based on content-length instead of authentication).

Implementation-wise, I would urge you to build this on top of routr ()if you plan to release it) as it makes it easier for others to add other pieces of functionality. The way I would do it is to check the server for existance of a header_routr plugin during attach_to. If it exists simply add the handler to the router, if not, create a new header routr with your handler and attach that to the server...

from fiery.

aneuraz avatar aneuraz commented on May 17, 2024

Thanks for your answer.
After looking at sizelimit_route, I wonder if it would not be easier to write a simple function like this instead of a plugin ?

from fiery.

thomasp85 avatar thomasp85 commented on May 17, 2024

Indeed, that is also possible... the upside of making it a plugin rather than a route is that the attached plugins can be queried from the app and other plugins can depend on your plugin - I agree that in this case it might be an edge case... may I ask what authentication you’re implementing?

from fiery.

aneuraz avatar aneuraz commented on May 17, 2024

it is for a JWT authentication

from fiery.

aneuraz avatar aneuraz commented on May 17, 2024

I commited a first draft of a JWT plugin here: https://github.com/aneuraz/JWTroutr
what do you think ?

from fiery.

thomasp85 avatar thomasp85 commented on May 17, 2024

Great - I’ll have a look through tomorrow or next week

from fiery.

thomasp85 avatar thomasp85 commented on May 17, 2024

Looks exactly like I would have imagined :-) I've made a little PR with some proposed changed but these are minor...

Are you planning on adding functionality for creating new tokens?

from fiery.

aneuraz avatar aneuraz commented on May 17, 2024

Thank you for the PR.
Regarding the creation of new tokens: yes! it is the next step

from fiery.

Related Issues (20)

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.