Giter Club home page Giter Club logo

ideas's People

Contributors

schnittstabil avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

ideas's Issues

ContentCharset

Middleware to negotiate the charset and convert the response body accordinly.

Middleware at the route level

More so than an idea I have a question on what the best approach is to handling middleware that needs to run for specific routes. For example I have some routes that a user needs to be logged in to access or they should be redirected to a login page. I also have checks for permissions and other items that could be ran as middleware for a specific route. Ideally I would like to define those items as part of the route definition. One of the ways I found to do this is have a dispatcher with the desired middlewares and a callable at the end of the middleware stack. Here is an example of what I mean:

  $r->addRoute(['GET', 'OPTIONS'], '/user/edit',
        new Dispatcher([
            // handler to redirect to login page if not logged in
            (new isNotLoggedInRedirectHandler),
            // handler to show access denied if user doesn't have permission
            (new PermissionsHandler)
                ->hasPermission(['editUser'),
            // code for the actual edit user page
            new CallableHandler( 'HandlerOnceTheseSpecificChecksHaveRun' )
        ])
    );

Although this approach does work I just wanted to see if this was an acceptable solution? Is there a "better" way to solve this issue?

`callable` utils

I'm planning to create 4 middleware related projects, allowing clients to additional deal with callable middlewares:

  1. middleware/is-delegate
  2. middleware/is-middleware
  3. middleware/to-delegate, casting/adapting DelegateInterface instances and callable delegates to DelegateInterface instances.
  4. middleware/to-middleware, casting/adapting MiddlewareInterface instances and callable delegates to MiddlewareInterface instances.

I'm always shilly shally about project names. For example:

  • is-delegatable sounds better, but
  • is-middlewarable may sounds weird, or doesn't it?

@middlewares/contributors Thoughts are welcome.

Encrypt/Decrypt cookies

A middleware to decrypt incoming and encrypt outgoing cookies.
It could use a JWT implementation or php-encription.

Maybe it could provide some security features:

  • Filter allowed cookies (and remove the others)
  • Ensure all cookies have directives like secure, httponly, etc...

Referring Route

I have some places where I check the referring route. In order to do this I had to create a function that produces the referring route and accounts for the base path. I haven't seen a middleware for this so I figured I would see if it makes sense to make this into a middleware.

function getRefererRoute(ServerRequestInterface $request, string $basePath) {
    $httpReferer = $request->getServerParams()["HTTP_REFERER"] ?? false;
    if ($httpReferer == false) {
        return "";
    }

    $parsedURL = parse_url($httpReferer);
    $route = $parsedURL['path'];

    if (substr($route, 0, strlen($basePath)) == $basePath) {
        $route = substr($route, strlen($basePath));
    }

    return $route;
}

PSR-15 compatible validation

I would like to see a module that allows pre-handler validation based on the name of the route and the method of the HTTP request.

For me the best option would be loading 'input_filter_specs' from a configuration referencing the route name and the HTTP method (something like ['login' => ['POST' => ], 'rottax' => ['GET' => ]]).

Thanks for the incredible work you're doing.

Best regards,
Massi.

IncludeResponse

This is something I did in psr7-middlewares. It's a middleware to include php files, usefull if you want to adapt old-style websites to the middleware approach. Let's say we have a website with the following files:

site/
    index.php
    about.php
    contact.php

Each page has it's own php file, so the urls are something like http://example.com/about.php, http://example.com/contact.php, etc. The middleware allow to use urls like http://example.com/about, include the php file, capture the output body and headers and return a response with that. It works as a wrapper for old websites.
I needed this in an old project and worked fine, the only problem I found was related with global variables, but was easy to solve.

league/route

Not sure about this, due league/route uses a double pass signature and PSR-15 has a single pass, so it is incompatible with other router sytems like aura.router and fastroute.
Anyway, a PSR-15 wrapper could be useful, creating the response before execute the route handler.

Mobile_Detect

For the PSR-7-middlewares there exist a Middleware which uses Mobile_Detect. This middleware is missing for PSR-15.

Cookies

A middleware to process incoming and outgoing cookies that can provide some functionalities:

  • Add automatically some flags like:
  • Encrypt/decrypt values
  • etc.

Pdf

A middleware to convert a html response to pdf. We can use something like this: https://github.com/KnpLabs/snappy
The workflow could be something like this:

  • A pdf request is received
  • The middleware converts to html request (optionally)
  • The middleware receives the html response
  • If the response is OK (200), converts to pdf and change the Content-Type.

Case insensitive URI

Not sure if this is already available, but a middleware that would make routes case insensitive could be useful. I ran into this recently with a route that I named "oAuth", but later tried to access using "oauth".

Remove X-Powered-By Header

There are instances where I don't want the 'X-Powered-By' header in my responses. Removing them can be a bit pesky though because PHP drops them into the response. To deal with it I put together a simple middleware that removes them. Not sure if it should have a repo, but I find it useful. See below:

<?php

declare(strict_types=1);

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

class RemovePoweredByHeader implements MiddlewareInterface {

    /**
     * Process a server request and return a response.
     */
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface {
       $response = $handler->handle($request);

       if (ini_get('expose_php')) {
              // prevent php from inserting a X-Powered-By header
              header_remove('X-Powered-By');
        }
        // remove the X-Powered-By header from the response
        return $response->withoutHeader('X-Powered-By');
        return $response;
    }
}

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.