Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/robrwo/plack-middleware-emulateoptions
handle OPTIONS requests as HEAD
https://github.com/robrwo/plack-middleware-emulateoptions
Last synced: 11 days ago
JSON representation
handle OPTIONS requests as HEAD
- Host: GitHub
- URL: https://github.com/robrwo/plack-middleware-emulateoptions
- Owner: robrwo
- Created: 2022-09-02T11:54:43.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-29T18:33:24.000Z (about 2 months ago)
- Last Synced: 2024-10-11T21:56:26.718Z (about 1 month ago)
- Language: Perl
- Size: 86.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: Changes
Awesome Lists containing this project
README
# NAME
Plack::Middleware::EmulateOPTIONS - handle OPTIONS requests as HEAD
# VERSION
version v0.4.0
# SYNOPSIS
```perl
use Plack::Builder;builder {
enable "EmulateOPTIONS",
filter => sub {
my $env = shift;
return $env->{PATH_INFO} =~ m[^/static/];
};...
};
```# DESCRIPTION
This middleware adds support for handling HTTP `OPTIONS` requests, by internally rewriting them as `HEAD` requests.
If the requests succeed, then it will add `Allow` headers using the ["callback"](#callback) method.
If the requests do not succeed, then the responses are passed unchanged.
You can add the ["filter"](#filter) attribute to determine whether it will proxy `HEAD` requests.
# ATTRIBUTES
## filter
This is an optional code reference for a function that takes the [PSGI](https://metacpan.org/pod/PSGI) environment and returns true or false as to
whether the request should be proxied.For instance, if you have CORS handler for a specific path, you might return false for those requests. Alternatively,
you might use the ["callback"](#callback).If you need a different value for the `Allow` headers, then you should handle the requests separately.
## callback
This is an optional code reference that modifies the response headers.
By default, it sets the `Allow` header to "GET, HEAD, OPTIONS".
If you override this, then you will need to manually set the header yourself, for example:
```perl
use Plack::Util;enable "EmulateOPTIONS",
callback => sub($res, $env) {my @allowed = qw( GET HEAD OPTIONS );
if ( $env->{PATH_INFO} =~ m[^/api/] ) {
push @allowed, qw( POST PUT DELETE );
}Plack::Util::header_set( $res->[1], 'allow', join(", ", @allowed) );
};
```This was added in v0.2.0.
# SUPPORT FOR OLDER PERL VERSIONS
Since v0.4.0, the this module requires Perl v5.20 or later.
Future releases may only support Perl versions released in the last ten years.
# SOURCE
The development version is on github at [https://github.com/robrwo/Plack-Middleware-EmulateOPTIONS](https://github.com/robrwo/Plack-Middleware-EmulateOPTIONS)
and may be cloned from [git://github.com/robrwo/Plack-Middleware-EmulateOPTIONS.git](git://github.com/robrwo/Plack-Middleware-EmulateOPTIONS.git)# BUGS
Please report any bugs or feature requests on the bugtracker website
[https://github.com/robrwo/Plack-Middleware-EmulateOPTIONS/issues](https://github.com/robrwo/Plack-Middleware-EmulateOPTIONS/issues)When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.# AUTHOR
Robert Rothenberg
# COPYRIGHT AND LICENSE
This software is Copyright (c) 2022-2024 by Robert Rothenberg.
This is free software, licensed under:
```
The Artistic License 2.0 (GPL Compatible)
```