Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/main/php/webservices/rest/RestUpload.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand Down
44 changes: 44 additions & 0 deletions src/test/php/webservices/rest/unittest/RestUploadTest.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '/'));
Expand Down
Loading