示例#1
0
 /**
  * Adds config values to the public properties when a new object is created.
  *
  * @param array $config Configuration options:
  *                      - `'status'`  _mixed_ : The response status (default: `[]`).
  *                      - `'cookies'` _array_ : set-cookie definition (default: `[]`).
  */
 public function __construct($config = [])
 {
     $defaults = ['status' => 200, 'location' => null, 'format' => 'html', 'cookies' => [], 'classes' => ['cookies' => 'Lead\\Net\\Http\\Cookie\\SetCookies']];
     $config = Set::merge($defaults, $config);
     parent::__construct($config);
     $this->status($config['status']);
     if ($config['location']) {
         $this->headers['Location'] = $config['location'];
     }
     $cookies = $this->_classes['cookies'];
     $this->headers->cookies = new $cookies(['data' => $config['cookies']]);
 }
示例#2
0
文件: Request.php 项目: crysalead/net
 /**
  * Auto adds a Content-Length header if necessary.
  *
  * @param object $request
  */
 public function _setContentLength()
 {
     if (in_array($this->method(), ['GET', 'HEAD', 'DELETE'], true)) {
         return;
     }
     parent::_setContentLength();
 }
示例#3
0
    describe("->get()", function () {
        it("decodes according to the Content-Type", function () {
            $message = new Message();
            $message->format("json");
            expect($message->body('""'))->toBe($message);
            expect($message->get())->toBe("");
            expect($message->body('{"name":"value"}'))->toBe($message);
            expect($message->get())->toBe(['name' => 'value']);
        });
    });
    describe("->line()", function () {
        it("retuns an empty string", function () {
            $message = new Message(['body' => 'Body Message']);
            expect($message->line())->toBe('');
        });
    });
    describe("->to()", function () {
        it("exports in JSON", function () {
            $message = new Message();
            expect($message->body('{"name":"value"}'))->toBe($message);
            expect($message->to('json'))->toBe(['name' => 'value']);
        });
        it("throws an exception with unsupported format", function () {
            $closure = function () {
                $message = new Message();
                $message->to('xml');
            };
            expect($closure)->toThrow(new InvalidArgumentException("Unsupported format `xml`."));
        });
    });
});