File: message011.phpt

package info (click to toggle)
php-pecl-http 3.1.0%2B2.6.0-4
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,060 kB
  • ctags: 3,725
  • sloc: ansic: 37,486; xml: 818; php: 635; pascal: 164; makefile: 2
file content (80 lines) | stat: -rw-r--r-- 1,741 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
--TEST--
message headers
--SKIPIF--
<?php
include "skipif.inc";
?>
--INI--
date.timezone=UTC
--FILE--
<?php

echo "Test\n";

class strval {
	private $str;
	function __construct($str) {
		$this->str = $str;
	}
	function __toString() {
		return (string) $this->str;
	}
}

$m = new http\Message;
$m->addHeaders(array("foo"=>"bar","bar"=>"foo"));
if (array("Foo"=>"bar", "Bar"=>"foo") !== $m->getHeaders()) {
	var_dump($m->getHeaders());
}
$m->addHeaders(array("key"=>"val","more"=>"Stuff"));
if (array("Foo"=>"bar", "Bar"=>"foo","Key"=>"val","More"=>"Stuff") !== $m->getHeaders()) {
	var_dump($m->getHeaders());
}
$m = new http\Message("GET / HTTP/1.1");
$m->addHeader("Accept", "text/html");
$m->addHeader("Accept", "text/xml;q=0");
$m->addHeader("Accept", "text/plain;q=0.5");
if (
		"GET / HTTP/1.1\r\n".
		"Accept: text/html, text/xml;q=0, text/plain;q=0.5\r\n" !==
		$m->toString()) {
	var_dump($m->toString());
}

$m = new http\Message("HTTP/1.1 200 Ok");
$m->addHeader("Bool", true);
$m->addHeader("Int", 123);
$m->addHeader("Float", 1.23);
$m->addHeader("Array", array(1,2,3));
$m->addHeader("Object", new strval("test"));
$m->addHeader("Set-Cookie",
		new http\Cookie(
				array(
						"cookies" => array("foo" => "bar"),
						"expires" => date_create("2012-12-31 22:59:59 GMT")->format(
								DateTime::COOKIE
						),
						"path" => "/somewhere"
				)
		)
);
$m->addHeader("Set-Cookie", "val=0");

if (
		"HTTP/1.1 200 Ok\r\n".
		"Bool: true\r\n".
		"Int: 123\r\n".
		"Float: 1.23\r\n".
		"Array: 1, 2, 3\r\n".
		"Object: test\r\n".
		"Set-Cookie: foo=bar; path=/somewhere; expires=Mon, 31 Dec 2012 22:59:59 GMT; \r\n".
		"Set-Cookie: val=0\r\n" !==
		$m->toString()) {
	var_dump($m->toString());
}

?>
Done
--EXPECT--
Test
Done