File tree 2 files changed +26
-1
lines changed
2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ public static function timeout($seconds)
84
84
*/
85
85
public static function defaultHeaders ($ headers )
86
86
{
87
- return array_merge (self ::$ defaultHeaders , $ headers );
87
+ return self :: $ defaultHeaders = array_merge (self ::$ defaultHeaders , $ headers );
88
88
}
89
89
90
90
/**
Original file line number Diff line number Diff line change @@ -39,6 +39,31 @@ public function testTimeoutFail()
39
39
Unirest \Request::timeout (null ); // Cleaning timeout for the other tests
40
40
}
41
41
42
+ public function testDefaultHeaders ()
43
+ {
44
+ $ defaultHeaders = array (
45
+ 'header1 ' => 'Hello ' ,
46
+ 'header2 ' => 'world '
47
+ );
48
+ Unirest \Request::defaultHeaders ($ defaultHeaders );
49
+
50
+ $ response = Unirest \Request::get ('http://mockbin.com/request ' );
51
+
52
+ $ this ->assertEquals (200 , $ response ->code );
53
+ $ this ->assertObjectHasAttribute ('header1 ' , $ response ->body ->headers );
54
+ $ this ->assertEquals ('Hello ' , $ response ->body ->headers ->header1 );
55
+ $ this ->assertObjectHasAttribute ('header2 ' , $ response ->body ->headers );
56
+ $ this ->assertEquals ('world ' , $ response ->body ->headers ->header2 );
57
+
58
+ Unirest \Request::clearDefaultHeaders ();
59
+
60
+ $ response = Unirest \Request::get ('http://mockbin.com/request ' );
61
+
62
+ $ this ->assertEquals (200 , $ response ->code );
63
+ $ this ->assertObjectNotHasAttribute ('header1 ' , $ response ->body ->headers );
64
+ $ this ->assertObjectNotHasAttribute ('header2 ' , $ response ->body ->headers );
65
+ }
66
+
42
67
public function testDefaultHeader ()
43
68
{
44
69
Unirest \Request::defaultHeader ('Hello ' , 'custom ' );
You can’t perform that action at this time.
0 commit comments