Giter Club home page Giter Club logo

mezzio-cors's Introduction

mezzio

Build Status Type Coverage

Develop PSR-7 middleware applications in minutes!

mezzio builds on laminas-stratigility to provide a minimalist PSR-7 middleware framework for PHP, with the following features:

Installation

We provide two ways to install Mezzio, both using Composer: via our skeleton project and installer, or manually.

Using the skeleton + installer

The simplest way to install and get started is using the skeleton project, which includes installer scripts for choosing a router, dependency injection container, and optionally a template renderer and/or error handler. The skeleton also provides configuration for officially supported dependencies.

To use the skeleton, use Composer's create-project command:

composer create-project mezzio/mezzio-skeleton <project dir>

This will prompt you through choosing your dependencies, and then create and install the project in the <project dir> (omitting the <project dir> will create and install in a mezzio-skeleton/ directory).

Manual Composer installation

You can install Mezzio standalone using Composer:

composer require mezzio/mezzio

However, at this point, Mezzio is not usable, as you need to supply minimally:

  • a router.
  • a dependency injection container.

We currently support and provide the following routing integrations:

We recommend using a dependency injection container, and typehint against PSR-11 Container. We can recommend the following implementations:

  • laminas-servicemanager: composer require laminas/laminas-servicemanager
  • Pimple (see docs for more details): composer require laminas/laminas-pimple-config
  • Aura.Di (see docs for more details): composer require laminas/laminas-auradi-config

Additionally, you may optionally want to install a template renderer implementation, and/or an error handling integration. These are covered in the documentation.

Documentation

Documentation is in the doc tree, and can be compiled using mkdocs:

mkdocs build

Additionally, public-facing, browseable documentation is available at https://docs.mezzio.dev/mezzio/

mezzio-cors's People

Contributors

acelaya avatar arueckauer avatar boesing avatar fezfez avatar froschdesign avatar geerteltink avatar ghostwriter avatar gsteel avatar laminas-bot avatar michalbundyra avatar ocramius avatar renovate[bot] avatar samsonasik avatar weierophinney avatar

Stargazers

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

Watchers

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

mezzio-cors's Issues

Guide for a quick start is needed

Problem

There is no description and code example that shows where the middleware must / can be inserted into a Mezzio application.

Suggestion

The basic usage with adding middleware and creating the configuration can be described in a quick start guide. A new page and navigation entry is needed for this.

Documentation: per-route configuration with Application::route

Documentation Needed

Summary

We do lacking documentation on how to configure per-route CORS options when not using the ApplicationConfigInjectionDelegator.

When using Application::route or one of the wrapper methods, it is not that obvious that the return value is the Route and thus it is possible to set the per-route options using Route::setOptions.

Documentation: allowed_origins format is wrong in examples

Bug Report

Q A
Version(s) 1.0.3

Summary

Documentation examples hint that allowed origins shall be defined with hostnames or domains but the extension expexts URI strings in a fnmatch pattern format. This is misleading and examples do not work.

Current behavior

Since documentation hints a wrong allowed origin URI format, extension does not work as expected.

How to reproduce

Use any simple domain as allowed origin, it will not match and will fall back to a 403 error.

Expected behavior

Either documentation should have examples with proper URL format.

Issue with Psr\Http\Message\UriFactoryInterface using mezzio swoole

Bug Report

Q A
Version(s) 1.0.1

Summary

Current behavior

While trying to use cors from installation page I see error below

Unable to resolve service "Psr\Http\Message\UriFactoryInterface" to a factory; are you certain you provided it during configuration?
triggered here https://github.com/mezzio/mezzio-cors/blob/1.1.x/src/Service/CorsFactory.php#L15
It seems one would have to specify a UriFactory mapped to this interface

How to reproduce

Expected behavior

`RouteConfigurationInterface::PARAMETER_IDENTIFIER` contains pre-migration `expressive` naming

Bug Report

Q A
Version(s) 1.0.4

Summary

The route configuration constant RouteConfigurationInterface::PARAMETER_IDENTIFIER contains expressive.cors and thus still contains the pre-migration value which I actually missed when porting to mezzio.

Current behavior

Constant value reflects expressive.cors.

How to reproduce

n/a

Expected behavior

Constant value reflects mezzio.cors.
When the constant value is changed, we should also grab the old route parameter expressive.cors from the configuration until the next major version.

Access-Control-Max-Age without value

Bug Report

Q A
Version(s) 1.0.1

Summary

Access-Control-Max-Age Currently returns an empty value if not set via the configuration. This does not adhere to the specification in which it should be either a deltatime (vumeric value) or be omitted.

Current behavior

If the Access-Control-Max-Age is not set, the preflight response still contains the Header but does not include a value.

How to reproduce

Omit the Access-Control-Max-Age Configuration entry for the global config and (if existing) the route specifig config. The OPTIONS Request will still contain the header but with no value.

Expected behavior

If no value is set, the header should be ommited from the response (or if easier for the implementation) contain a default value.

Issue with non http and https Origins

Bug Report

Q A
Version(s) x.y.z

Summary

When a request is made from an origin that its scheme is not http(s), the pre flight request fails and we understand that this may be caused by the URI factory

Current behavior

When our Origin is capacitor://xyz.com, pre flight request fails

How to reproduce

Make a preflight request with a non http(s) scheme

Expected behavior

Preflight and CORS request should proceed as this is a valid URI

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Repository problems

These problems occurred while renovating this repository. View logs.

  • WARN: Use matchDepNames instead of matchPackageNames

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • Lock file maintenance

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

composer
composer.json
  • php ~8.1.0 || ~8.2.0 || ~8.3.0
  • fig/http-message-util ^1.1
  • mezzio/mezzio-router ^3.1
  • psr/container ^1.0 || ^2.0
  • psr/http-factory ^1.0
  • psr/http-message ^1.0 || ^2.0
  • psr/http-server-handler ^1.0
  • psr/http-server-middleware ^1.0
  • webmozart/assert ^1.11.0
  • laminas/laminas-coding-standard ~2.5.0
  • laminas/laminas-diactoros ^3.3.1
  • phpunit/phpunit ^10.5.11
  • psalm/plugin-phpunit ^0.19.0
  • vimeo/psalm ^5.22.2
github-actions
.github/workflows/continuous-integration.yml
.github/workflows/docs-build.yml
.github/workflows/release-on-milestone-closed.yml

  • Check this box to trigger a request for Renovate to run again on this repository

Provided Origin "capacitor://localhost" is an invalid

Bug Report

Mezzio\Cors\Exception\InvalidOriginValueException raised in file /vendor/mezzio/mezzio-cors/src/Exception/InvalidOriginValueException.php in line 21 with message: Provided Origin "capacitor://localhost" is invalid.

Q A
Version(s) 1.3.0

Summary

While running IOS Simulator in XCode, An Exception is raised from the mezzio-cors package.

Current behavior

The exception is raised on every request comes from the cliend side (XCode Simulator). mezzio-cors claims that capacitor://localhost is invalid origin

How to reproduce

in pipeline.php

use Mezzio\Cors\Middleware\CorsMiddleware;

$app->pipe(CorsMiddleware::class);

Expected behavior

Should be able to add the capacitor://localhost to the allowed origins

return [
    ConfigurationInterface::CONFIGURATION_IDENTIFIER => [
        'allowed_origins' => ['capacitor://localhost', 'http://localhost'],
        'allowed_headers' => ['Content-Type', ' Access-Control-Allow-Headers', 'Authorization'],
        'allowed_max_age' => '3600',
        'credentials_allowed' => true,
        'exposed_headers' => []
    ],

PS. This is my first bug report ;)

Explicit option in the route options

Bug Report

It seems that the explicit option does currently not work and will always be overwritten.

Q A
Version(s) 1.0.1

Summary

Explicit route options are not possible and thus project config will always overwrite route config.

Current behavior

Setting the explicit option on a route is not possible, as it will always be overwritten by the ConfigurationLocator

How to reproduce

The example provided in "Enable Project Merging" should already fail, as "explicit" is overwritten due to

private function explicit(array $allowedMethods): bool
{
    return $allowedMethods === CorsMetadata::ALLOWED_REQUEST_METHODS;
}

failing if $allowedMethods is i.e. only 'GET'

Expected behavior

If explicit is set on a route it should not be overwritten.

Likely wrong PHP version declaration

PHP declaration in composer.json feels wrong:

"php": "^7.4 || ^8.0 || ~8.1.0"

it should either be "^7.4 || ~8.0.0 || ~8.1.0" like in other mezzio packages to control PHP 8.x support or "^7.4 || ^8.0" to show that any 8.x is supported

Not really a bug but a smelly declaration

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.