Permalink
Browse files

Stripping out the path to a file in the Content-Disposition of a POST…

… file. Addresses #55.
  • Loading branch information...
mtdowling committed Sep 20, 2012
1 parent 2fa1b69 commit 46d50a31cc9e7d974a1b989c6a66b311ce05ed9b
@@ -93,9 +93,11 @@ public function getContentType()
*/
public function getCurlString()
{
+ $disposition = ';filename=' . basename($this->filename);
+
return $this->contentType
- ? '@' . $this->filename . ';type=' . $this->contentType
- : '@' . $this->filename;
+ ? '@' . $this->filename . ';type=' . $this->contentType . $disposition
+ : '@' . $this->filename . $disposition;
}
/**
@@ -377,7 +377,7 @@ public function dataProvider()
CURLOPT_ENCODING => '',
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => array(
- 'file' => '@' . $testFile . ';type=application/xml'
+ 'file' => '@' . $testFile . ';type=application/xml;filename=phpunit.xml.dist'
),
CURLOPT_HTTPHEADER => array (
'Host: localhost:8124',
@@ -2,10 +2,12 @@
namespace Guzzle\Tests\Http\Message;
+use Guzzle\Http\Client;
use Guzzle\Http\Message\PostFile;
/**
* @covers Guzzle\Http\Message\PostFile
+ * @group server
*/
class PostFileTest extends \Guzzle\Tests\GuzzleTestCase
{
@@ -50,4 +52,16 @@ public function testReturnsCurlValueString()
$file = new PostFile('foo', __FILE__);
$this->assertContains('@' . __FILE__ . ';type=text/x-', $file->getCurlString());
}
+
+ public function testContentDispositionFilePathIsStripped()
+ {
+ $this->getServer()->flush();
+ $client = new Client($this->getServer()->getUrl());
+ $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n");
+ $request = $client->post()->addPostFile('file', __FILE__);
+ $request->send();
+ $requests = $this->getServer()->getReceivedRequests(false);
+ $this->assertContains('POST / HTTP/1.1', $requests[0]);
+ $this->assertContains('Content-Disposition: form-data; name="file"; filename="PostFileTest.php"', $requests[0]);
+ }
}

0 comments on commit 46d50a3

Please sign in to comment.