/** * This function is used to send a multipart request (blob + request) to Nuxeo EM, such as the attachBlob request * @return string */ private function multiPart() { if (sizeof($this->blobList) > 1 and !isset($this->finalRequest['params']['xpath'])) { $this->finalRequest['params']['xpath'] = 'files:files'; } $content = str_replace('\\/', '/', json_encode($this->finalRequest)); $this->headers = array($this->headers, 'Content-ID: request'); $requestheaders = 'Content-Type: application/json+nxrequest; charset=UTF-8' . "\r\n" . 'Content-Transfer-Encoding: 8bit' . "\r\n" . 'Content-ID: request' . "\r\n" . 'Content-Length:' . strlen($content) . "\r\n" . "\r\n"; $value = sizeof($this->blobList); $boundary = '====Part=' . time() . '=' . (int) rand(0, 1000000000) . '==='; $data = "--" . $boundary . "\r\n" . $requestheaders . $content . "\r\n" . "\r\n"; for ($cpt = 0; $cpt < $value; $cpt++) { $data = $data . "--" . $boundary . "\r\n"; $blobheaders = 'Content-Type:' . $this->blobList[$cpt][1] . "\r\n" . 'Content-ID: input' . "\r\n" . 'Content-Transfer-Encoding: binary' . "\r\n" . 'Content-Disposition: attachment;filename="' . $this->blobList[$cpt][0] . '"' . "\r\n" . "\r\n"; $data = "\r\n" . $data . $blobheaders . $this->blobList[$cpt][2] . "\r\n"; } $this->request->setBody($data . "--" . $boundary . "--"); $this->request->setHeader('Accept', 'application/json+nxentity, */*'); $this->request->setHeader('Content-Type', 'multipart/related;boundary="' . $boundary . '";type="application/json+nxrequest";start="request"'); $this->request->setHeader(self::HEADER_NXVoidOperation, $this->NXVoidOperation); $response = $this->request->send(); $answer = json_decode($response->getBody(true), true); return $answer; }
/** * @covers Guzzle\Http\Message\EntityEnclosingRequest::setExpectHeaderCutoff * @covers Guzzle\Http\Message\EntityEnclosingRequest::setBody */ public function testSettingExpectHeaderCutoffChangesRequest() { $request = new EntityEnclosingRequest('PUT', 'http://test.com/'); $request->setHeader('Expect', '100-Continue'); $request->setExpectHeaderCutoff(false); $this->assertNull($request->getHeader('Expect')); // There is not body, so remove the expect header $request->setHeader('Expect', '100-Continue'); $request->setExpectHeaderCutoff(10); $this->assertNull($request->getHeader('Expect')); // The size is less than the cutoff $request->setBody('foo'); $this->assertNull($request->getHeader('Expect')); // The size is greater than the cutoff $request->setBody('foobazbarbamboo'); $this->assertNotNull($request->getHeader('Expect')); }