Closed lpj145 closed 7 years ago
The above code does not seem to be from my cors middleware?
above is a simple cors middleware, i can't implement you middleware.
Ah yes now I understand. There is no PSR-15 support yet because PSR-15 is not finalized. However Expressive has a PSR-15 wrapper for PSR-7 style middlewares.
oh, its song good for me, i need make factory to do it ?
Zend Expressive 2 wraps automatically, actually it is Zend Stratigility that does the wrapping, so it just works, nothing else needs to be done. https://github.com/zendframework/zend-stratigility/blob/master/src/MiddlewarePipe.php#L135 and https://github.com/zendframework/zend-stratigility/blob/master/src/MiddlewarePipe.php#L224
@Xerkus that is what I thought.
@lpj145 Can you show example code how you initialise the middleware and an example curl request which fails. For example:
$ curl "https://api.example.com/foo" \
--request OPTIONS \
--include \
--header "Origin: http://www.example.com" \
--header "Access-Control-Request-Method: PUT" \
--header "Access-Control-Request-Headers: Authorization, If-Match"
Copy pasting code is preferred over screenshots. When testing copy paste my curl command exactly except the url. For example you should use --header "Origin: http://www.example.com"
not --header "Origin: http//:www.example.com"
curl lvh.me/ -v --request OPTIONS --include --header "Origin: http://www.example.com" --header "Access-Control-Request-Method: PUT"
You can use three ` characters to format the code.
curl lvh.me/ -v --request OPTIONS --include --header "Origin: ht" --header "Access-Control-Request-Method: PUT"
I'm very grateful for that.
I just tested with the latest Expressive and everything seems to be working as exptected. Code copied from examples.
<?php
use Interop\Http\ServerMiddleware\DelegateInterface;
use Zend\Diactoros\Response\TextResponse;
use Zend\Expressive\AppFactory;
chdir(dirname(__DIR__));
require "vendor/autoload.php";
$app = AppFactory::create();
$app->get("/", function ($request, DelegateInterface $delegate) {
return new TextResponse("Hello, world!");
});
$app->pipe(new Tuupola\Middleware\Cors([
"origin" => ["*"],
"methods" => ["GET", "POST", "PUT", "PATCH", "DELETE"],
"headers.allow" => [],
"headers.expose" => [],
"credentials" => false,
"cache" => 0,
]));
$app->pipeRoutingMiddleware();
$app->pipeDispatchMiddleware();
$app->run();
$ curl http://localhost:8081 --include --header "Origin: http://example.com"
HTTP/1.1 200 OK
Host: localhost:8081
Date: Wed, 20 Sep 2017 13:09:03 +0000
Connection: close
X-Powered-By: PHP/7.1.6
Content-Type: text/plain; charset=utf-8
Access-Control-Allow-Origin: http://example.com
Vary: Origin
Hello, world!
On last version of zend expressive https://docs.zendframework.com/zend-expressive/
The cors not works right!
When i:
i think it not pass to cors on next function.