Skip to content

Commit

Permalink
better multipart/form-data fix
Browse files Browse the repository at this point in the history
  • Loading branch information
spacedevin committed May 24, 2016
1 parent 00855dc commit 3dac011
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ public function __construct($args = []) {
case 'POST':
if ($this->_contentType() === 'application/json') {
$this->_properties = json_decode($this->content(), 'array');
// } elseif ($_SERVER['CONTENT_TYPE'] === 'application/x-www-form-urlencoded') {
} elseif ($this->_contentType() === 'multipart/form-data') {
$this->_properties = $_REQUEST;
} else {
$this->_properties = $_POST;
$this->_properties = $_REQUEST;
}
break;

Expand Down
22 changes: 22 additions & 0 deletions tests/RestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ public function setUp() {
$this->setupDb($this->tip);
}

public function testMultipartFormPost() {
$_REQUEST['__url'] = 'test';
$_SERVER['REQUEST_METHOD'] = 'POST';
$_SERVER['CONTENT_TYPE'] = 'multipart/form-data; separater blah blah';
$_REQUEST['data'] = 'blah';

$this->tip->service('TestModel', []);

$this->tip->router()
->post('test',function($TestModel, $Request) {
$TestModel->test = 'hi';
$TestModel->data = $Request->data;
echo $TestModel->json();
});

$this->ob();
$this->tip->run();
$check = $this->ob(false);
$this->assertEquals(json_encode(['test' => 'hi', 'data' => 'blah']), $check);
}


public function testFormPost() {
$_REQUEST['__url'] = 'test';
$_SERVER['REQUEST_METHOD'] = 'POST';
Expand Down

0 comments on commit 3dac011

Please sign in to comment.