Giter VIP home page Giter VIP logo

plack-middleware-mockproxyfrontend's Introduction

NAME

Plack::Middleware::MockProxyFrontend - virtualhost-aware PSGI app developer tool

SYNOPSIS

# in app.psgi
use Plack::Builder;

builder {
    enable 'MockProxyFrontend',
        SSL_key_file  => 'key.pem',
        SSL_cert_file => 'cert.pem';
    $app;
};

DESCRIPTION

This middleware implements the HTTP proxy protocol… without the proxy: it passes every request down to the wrapped PSGI application. Your application becomes the browser's entire internet: no matter which address you navigate to, the response comes from the wrapped PSGI application.

This is useful in the development of PSGI applications that do virtual hosting, i.e. dispatching on hostname. Instead of testing your application by going to http://localhost:5000/, you go to https://example.com/ (or whatever your site is). Your application will see a request for https://example.com/, not http://localhost:5000/, e.g. when your framework generates absolute links. And then when the page loads, the browser will think it is showing you the real https://example.com/, e.g. in the address bar.

The way this works is that instead of typing http://localhost:5000/ into the browser's address bar to test your app (or wherever your development server is listening), you put localhost:5000 as the HTTP/HTTPS proxy in the browser's configuration. Then any URL you navigate to will end up being served by your application, so e.g. absolute links to https://example.com/ will just work.

NOTE

If you use plackup to start your application, use --no-default-middleware to prevent it wrapping Plack::Middleware::Lint around this middleware. Lint reacts badly to a browser speaking the proxy protocol to it.

Generally MockProxyFrontend ought to be the outermost middleware in your stack. Most other middlewares will work OK when confronted with the proxy protocol, but they are not really designed for it, so it is best to convert the request to a normal HTTP request as soon as possible.

CONFIGURATION OPTIONS

SSL_*

Configuration options for IO::Socket::SSL that will be used to construct an SSL context.

You don't need to pass any of these unless you need SSL support. If you need it, SSL_key_file and SSL_cert_file are probably the options you are looking for.

Note that SSL support requires a PSGI server that implements the psgix.io extension.

host_acceptor

A function that will be called to decide whether to serve a request. If it returns false, the request will be refused, otherwise it will be served. The function will be passed the (lowercased) hostname from the request, both as its sole argument and in $_. E.g.:

enable 'MockProxyFrontend',
    host_acceptor => sub { 'webmonkeys.io' eq $_ };

Defaults to accepting all requests.

http_server

An object that responds to $self->handle_connection( $env, $socket, $app ). This will be passed the connection from CONNECT requests. E.g.:

enable 'MockProxyFrontend',
    http_server => do {
        require Starlet::Server;
        Starlet::Server->new
    };

Defaults to an instance of HTTP::Server::PSGI.

BUGS AND LIMITATIONS

Error checking and attitude toward security is lackadaiscal.

There are NO TESTS because I wouldn't know how to write them.

This was written as a developer tool, not for deployment anywhere that could be described as production. Otherwise I wouldn't be releasing it in this state.

Use at your own risk.

Mind you, I am anything but opposed to fixing these problems – I am just not losing sleep over them. Patches welcome and highly appreciated.

plack-middleware-mockproxyfrontend's People

Contributors

ap avatar

Watchers

 avatar  avatar  avatar  avatar

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.