Esempio n. 1
0
 public function testResponse()
 {
     $content = 'HTML Content';
     $response = new Response($content);
     $this->assertEquals('no-cache', $response->getHeaderLine('Cache-Control'));
     $this->assertEquals('text/html;charset=UTF-8', $response->getHeaderLine('Content-Type'));
     $this->assertEquals(29, strlen($response->getHeaderLine('Date')));
     $this->assertEquals($content, $response->getParsedBody());
 }
Esempio n. 2
0
 public function testCors()
 {
     $listener = new CorsListener();
     $headers = ['Origin' => 'localhost'];
     $request = new Request('GET /resource', $headers);
     $response = new Response();
     $event = new KernelResponseEvent($request, $response);
     $listener->onKernelResponse($event);
     $responsex = $event->getResponse();
     $this->assertFalse($response->hasHeader('Access-Control-Allow-Origin'));
     $this->assertEquals('localhost', $responsex->getHeaderLine('Access-Control-Allow-Origin'));
 }
Esempio n. 3
0
File: app.php Progetto: cerad/http
require __DIR__ . '/../vendor/autoload.php';
use Cerad\Component\HttpMessage\Request as CeradRequest;
use Cerad\Component\HttpMessage\Response;
use Cerad\Component\HttpMessage\ResponseJson;
use Symfony\Component\HttpFoundation\Request as SymfonyRequest;
//  Symfony\Component\HttpFoundation\Response     as SymfonyResponse;
//  Symfony\Component\HttpFoundation\JsonResponse as SymfonyJsonResponse;
$ceradRequest = new CeradRequest($_SERVER);
$ceradUri = $ceradRequest->getUri();
$ceradServer = $ceradRequest->getServerParams();
$symfonyRequest = SymfonyRequest::createFromGlobals();
$user = '******';
$baseHref = $ceradRequest->getBaseHref();
$_serverPathInfo = isset($_SERVER['PATH_INFO']) ? $_SERVER['PATH_INFO'] : 'UNDEFINED';
if ($ceradRequest->isMethodPost()) {
    $content = $ceradRequest->getParsedBody();
    $user = $content['user'];
    if ($ceradRequest->isJson()) {
        $response = new ResponseJson($content, 201);
        $response->send();
        return;
    }
    if ($ceradRequest->isForm()) {
        // Redirect if had a session to store things in
    }
}
ob_start();
require 'app.html';
$html = ob_get_clean();
$response = new Response($html);
$response->send();