public function testMultipartWithAmpersandInValue() { $b = new PostBody(); $b->setField('a', 'b&c=d'); $b->forceMultipartUpload(true); $this->assertEquals(['a' => 'b&c=d'], $b->getFields()); $m = new Request('POST', '/'); $b->applyRequestHeaders($m); $this->assertContains('multipart/form-data', $m->getHeader('Content-Type')); $this->assertTrue($m->hasHeader('Content-Length')); $contents = $b->getContents(); $this->assertContains('name="a"', $contents); $this->assertContains('b&c=d', $contents); }
/** * Apply POST fields and files to a request to attempt to give an accurate * representation. * * @param RequestInterface $request Request to update * @param array $body Body to apply */ protected function addPostData(RequestInterface $request, array $body) { static $fields = ['string' => true, 'array' => true, 'NULL' => true, 'boolean' => true, 'double' => true, 'integer' => true]; $post = new PostBody(); foreach ($body as $key => $value) { if (isset($fields[gettype($value)])) { $post->setField($key, $value); } elseif ($value instanceof PostFileInterface) { $post->addFile($value); } else { $post->addFile(new PostFile($key, $value)); } } if ($request->getHeader('Content-Type') == 'multipart/form-data') { $post->forceMultipartUpload(true); } $request->setBody($post); }