Browse Source

Add deprecation warning for #16698

Mark Story 3 years ago
parent
commit
e6f184d1fe
3 changed files with 20 additions and 7 deletions
  1. 2 2
      src/Http/Response.php
  2. 3 0
      src/Http/ServerRequest.php
  3. 15 5
      tests/TestCase/Http/ServerRequestTest.php

+ 2 - 2
src/Http/Response.php

@@ -1387,9 +1387,9 @@ class Response implements ResponseInterface
     public function cors(ServerRequest $request): CorsBuilder
     {
         $origin = $request->getHeaderLine('Origin');
-        $ssl = $request->is('ssl');
+        $https = $request->is('https');
 
-        return new CorsBuilder($this, $origin, $ssl);
+        return new CorsBuilder($this, $origin, $https);
     }
 
     /**

+ 3 - 0
src/Http/ServerRequest.php

@@ -529,6 +529,9 @@ class ServerRequest implements ServerRequestInterface
      */
     protected function _is(string $type, array $args): bool
     {
+        if ($type === 'ssl') {
+            deprecationWarning('The `ssl` detector is deprecated. Use `https` instead.');
+        }
         $detect = static::$_detectors[$type];
         if (is_callable($detect)) {
             array_unshift($args, $this);

+ 15 - 5
tests/TestCase/Http/ServerRequestTest.php

@@ -746,24 +746,34 @@ class ServerRequestTest extends TestCase
         $request = new ServerRequest();
 
         $request = $request->withEnv('HTTPS', 'on');
-        $this->assertTrue($request->is('ssl'));
         $this->assertTrue($request->is('https'));
+        $this->deprecated(function () use ($request) {
+            $this->assertTrue($request->is('ssl'));
+        });
 
         $request = $request->withEnv('HTTPS', '1');
-        $this->assertTrue($request->is('ssl'));
         $this->assertTrue($request->is('https'));
+        $this->deprecated(function () use ($request) {
+            $this->assertTrue($request->is('ssl'));
+        });
 
         $request = $request->withEnv('HTTPS', 'I am not empty');
-        $this->assertFalse($request->is('ssl'));
         $this->assertFalse($request->is('https'));
+        $this->deprecated(function () use ($request) {
+            $this->assertFalse($request->is('ssl'));
+        });
 
         $request = $request->withEnv('HTTPS', 'off');
-        $this->assertFalse($request->is('ssl'));
         $this->assertFalse($request->is('https'));
+        $this->deprecated(function () use ($request) {
+            $this->assertFalse($request->is('ssl'));
+        });
 
         $request = $request->withEnv('HTTPS', '');
-        $this->assertFalse($request->is('ssl'));
         $this->assertFalse($request->is('https'));
+        $this->deprecated(function () use ($request) {
+            $this->assertFalse($request->is('ssl'));
+        });
     }
 
     /**