Exemplo n.º 1
0
 public function testApplyingWithFieldsAddsMultipartUpload()
 {
     $b = new PostBody();
     $b->setField('foo', 'bar');
     $this->assertEquals(['foo' => 'bar'], $b->getFields());
     $m = new Request('POST', '/');
     $b->applyRequestHeaders($m);
     $this->assertContains('application/x-www-form', (string) $m->getHeader('Content-Type'));
     $this->assertTrue($m->hasHeader('Content-Length'));
 }
Exemplo n.º 2
0
 public function testDoesNotOverwriteExistingHeaderForUrlencoded()
 {
     $m = new Request('POST', 'http://foo.com', ['content-type' => 'application/x-www-form-urlencoded; charset=utf-8']);
     $b = new PostBody();
     $b->setField('foo', 'bar');
     $b->applyRequestHeaders($m);
     $this->assertEquals('application/x-www-form-urlencoded; charset=utf-8', $m->getHeader('Content-Type'));
 }
Exemplo n.º 3
0
 public function testMultipartWithBase64Fields()
 {
     $b = new PostBody();
     $b->setField('foo64', '/xA2JhWEqPcgyLRDdir9WSRi/khpb2Lh3ooqv+5VYoc=');
     $b->forceMultipartUpload(true);
     $this->assertEquals(['foo64' => '/xA2JhWEqPcgyLRDdir9WSRi/khpb2Lh3ooqv+5VYoc='], $b->getFields());
     $m = new Request('POST', '/');
     $b->applyRequestHeaders($m);
     $this->assertContains('multipart/form-data', (string) $m->getHeader('Content-Type'));
     $this->assertTrue($m->hasHeader('Content-Length'));
     $contents = $b->getContents();
     $this->assertContains('name="foo64"', $contents);
     $this->assertContains('/xA2JhWEqPcgyLRDdir9WSRi/khpb2Lh3ooqv+5VYoc=', $contents);
 }
Exemplo n.º 4
0
 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);
 }