diff --git a/src/main/php/webservices/rest/RestUpload.class.php b/src/main/php/webservices/rest/RestUpload.class.php index 24ccb74..a51b389 100755 --- a/src/main/php/webservices/rest/RestUpload.class.php +++ b/src/main/php/webservices/rest/RestUpload.class.php @@ -35,6 +35,28 @@ public function waiting($read= null, $connect= null) { return $this; } + /** + * Adds given headers + * + * @param [:string] $headers + * @return self + */ + public function with($headers) { + $this->request->add($headers); + return $this; + } + + /** + * Includes given cookies + * + * @param [:?string]|webservices.rest.Cookie[]|webservices.rest.Cookies $cookies + * @return self + */ + public function including($cookies) { + $this->request->including($cookies); + return $this; + } + /** @return webservices.rest.io.Parts */ public function open() { return new Parts(self::BOUNDARY, $this->endpoint->open($this->request->with([ diff --git a/src/test/php/webservices/rest/unittest/RestUploadTest.class.php b/src/test/php/webservices/rest/unittest/RestUploadTest.class.php index a581c75..91700ef 100755 --- a/src/test/php/webservices/rest/unittest/RestUploadTest.class.php +++ b/src/test/php/webservices/rest/unittest/RestUploadTest.class.php @@ -50,6 +50,50 @@ public function pass_parameter() { ); } + #[Test] + public function with_headers() { + $upload= new RestUpload($this->newEndpoint(), new RestRequest('POST', '/')); + $upload->with(['X-Test' => 'true'])->pass('name', 'Test'); + + Assert::equals( + "POST / HTTP/1.1\r\n". + "Connection: close\r\n". + "Host: test\r\n". + "X-Test: true\r\n". + "Content-Type: multipart/form-data; boundary=---------------boundary1xp6132872336bc4\r\n". + "Transfer-Encoding: chunked\r\n". + "\r\n". + "-----------------boundary1xp6132872336bc4\r\n". + "Content-Disposition: form-data; name=\"name\"\r\n". + "\r\n". + "Test\r\n". + "-----------------boundary1xp6132872336bc4--\r\n", + $upload->finish()->content() + ); + } + + #[Test] + public function including_cookies() { + $upload= new RestUpload($this->newEndpoint(), new RestRequest('POST', '/')); + $upload->including(['session_id' => '1234'])->pass('name', 'Test'); + + Assert::equals( + "POST / HTTP/1.1\r\n". + "Connection: close\r\n". + "Host: test\r\n". + "Content-Type: multipart/form-data; boundary=---------------boundary1xp6132872336bc4\r\n". + "Transfer-Encoding: chunked\r\n". + "Cookie: session_id=1234\r\n". + "\r\n". + "-----------------boundary1xp6132872336bc4\r\n". + "Content-Disposition: form-data; name=\"name\"\r\n". + "\r\n". + "Test\r\n". + "-----------------boundary1xp6132872336bc4--\r\n", + $upload->finish()->content() + ); + } + #[Test] public function transfer_file() { $upload= new RestUpload($this->newEndpoint(), new RestRequest('POST', '/'));