2626 */
2727class Request {
2828 /** @var \DCarbone\PHPConsulAPI\Values */
29- public $ headers ;
29+ public $ Headers ;
3030 /** @var \DCarbone\PHPConsulAPI\Params */
31- public $ params ;
31+ public $ Params ;
3232
3333 /** @var \DCarbone\PHPConsulAPI\Config */
3434 private $ config ;
@@ -56,24 +56,24 @@ public function __construct($method, $path, Config $config, $body = null) {
5656 $ this ->config = $ config ;
5757
5858 $ this ->method = strtoupper ($ method );
59- $ this ->path = $ path ;
59+ $ this ->path = $ path ; // TODO: perform some kind of path input validation?
6060
61- $ this ->headers = new Values ();
62- $ this ->params = new Params ();
61+ $ this ->Headers = new Values ();
62+ $ this ->Params = new Params ();
6363
6464 if ('' !== $ config ->Datacenter ) {
65- $ this ->params ->set ('dc ' , $ config ->Datacenter );
65+ $ this ->Params ->set ('dc ' , $ config ->Datacenter );
6666 }
6767
6868 if (0 !== $ config ->WaitTime ) {
69- $ this ->params ->set ('wait ' , $ config ->intToMillisecond ($ config ->WaitTime ));
69+ $ this ->Params ->set ('wait ' , $ config ->intToMillisecond ($ config ->WaitTime ));
7070 }
7171
7272 if ('' !== $ config ->Token ) {
7373 if ($ config ->TokenInHeader ) {
74- $ this ->headers ->set ('X-Consul-Token ' , $ config ->Token );
74+ $ this ->Headers ->set ('X-Consul-Token ' , $ config ->Token );
7575 } else {
76- $ this ->params ->set ('token ' , $ config ->Token );
76+ $ this ->Params ->set ('token ' , $ config ->Token );
7777 }
7878 }
7979
@@ -121,40 +121,40 @@ public function setQueryOptions(QueryOptions $options = null) {
121121 }
122122
123123 if ('' !== $ options ->Datacenter ) {
124- $ this ->params ->set ('dc ' , $ options ->Datacenter );
124+ $ this ->Params ->set ('dc ' , $ options ->Datacenter );
125125 }
126126 if ($ options ->AllowStale ) {
127- $ this ->params ->set ('stale ' , '' );
127+ $ this ->Params ->set ('stale ' , '' );
128128 }
129129 if ($ options ->RequireConsistent ) {
130- $ this ->params ->set ('consistent ' , '' );
130+ $ this ->Params ->set ('consistent ' , '' );
131131 }
132132 if (0 !== $ options ->WaitIndex ) {
133- $ this ->params ->set ('index ' , (string )$ options ->WaitIndex );
133+ $ this ->Params ->set ('index ' , (string )$ options ->WaitIndex );
134134 }
135135 if (0 !== $ options ->WaitTime ) {
136- $ this ->params ->set ('wait ' , $ this ->config ->intToMillisecond ($ options ->WaitTime ));
136+ $ this ->Params ->set ('wait ' , $ this ->config ->intToMillisecond ($ options ->WaitTime ));
137137 }
138138 if ('' !== $ options ->Token ) {
139139 if ($ this ->config ->TokenInHeader ) {
140- $ this ->headers ->set ('X-Consul-Token ' , $ options ->Token );
140+ $ this ->Headers ->set ('X-Consul-Token ' , $ options ->Token );
141141 } else {
142- $ this ->params ->set ('token ' , $ options ->Token );
142+ $ this ->Params ->set ('token ' , $ options ->Token );
143143 }
144144 }
145145 if ('' !== $ options ->Near ) {
146- $ this ->params ->set ('near ' , $ options ->Near );
146+ $ this ->Params ->set ('near ' , $ options ->Near );
147147 }
148148 if (isset ($ options ->NodeMeta ) && 0 < count ($ options ->NodeMeta )) {
149149 foreach ($ options ->NodeMeta as $ k => $ v ) {
150- $ this ->params ->add ('node-meta ' , "{$ k }: {$ v }" );
150+ $ this ->Params ->add ('node-meta ' , "{$ k }: {$ v }" );
151151 }
152152 }
153- if ('' !== $ options ->RelayFactor ) {
154- $ this ->params ->set ('relay-factor ' , (string )$ options ->RelayFactor );
153+ if (0 !== $ options ->RelayFactor ) {
154+ $ this ->Params ->set ('relay-factor ' , (string )$ options ->RelayFactor );
155155 }
156156 if ($ options ->Pretty ) {
157- $ this ->params ->set ('pretty ' , '' );
157+ $ this ->Params ->set ('pretty ' , '' );
158158 }
159159
160160 $ this ->uri = null ;
@@ -169,17 +169,17 @@ public function setWriteOptions(WriteOptions $options = null) {
169169 }
170170
171171 if ('' !== $ options ->Datacenter ) {
172- $ this ->params ->set ('dc ' , $ options ->Datacenter );
172+ $ this ->Params ->set ('dc ' , $ options ->Datacenter );
173173 }
174174 if ('' !== $ options ->Token ) {
175175 if ($ this ->config ->TokenInHeader ) {
176- $ this ->headers ->set ('X-Consul-Token ' , $ options ->Token );
176+ $ this ->Headers ->set ('X-Consul-Token ' , $ options ->Token );
177177 } else {
178- $ this ->headers ->set ('token ' , $ options ->Token );
178+ $ this ->Headers ->set ('token ' , $ options ->Token );
179179 }
180180 }
181181 if (0 !== $ options ->RelayFactor ) {
182- $ this ->params ->set ('relay-factor ' , (string )$ options ->RelayFactor );
182+ $ this ->Params ->set ('relay-factor ' , (string )$ options ->RelayFactor );
183183 }
184184
185185 $ this ->uri = null ;
@@ -190,9 +190,15 @@ public function setWriteOptions(WriteOptions $options = null) {
190190 */
191191 public function getUri () {
192192 if (!isset ($ this ->uri )) {
193- $ uri = sprintf ('%s://%s/%s ' , $ this ->config ->getScheme (), $ this ->config ->Address , $ this ->path );
194- if (0 < count ($ this ->params )) {
195- $ uri = sprintf ('%s?%s ' , $ uri , (string )$ this ->params );
193+ $ uri = sprintf (
194+ '%s://%s/%s ' ,
195+ $ this ->config ->getScheme (),
196+ $ this ->config ->Address ,
197+ ltrim (rtrim ($ this ->path , " \t\n\r\0\x0B&? " ),
198+ " \t\n\r\0\x0B/ " ) // TODO: Lessen # of things being looked for?
199+ );
200+ if (0 < count ($ this ->Params )) {
201+ $ uri = sprintf ('%s?%s ' , $ uri , (string )$ this ->Params );
196202 }
197203 $ this ->uri = new Uri ($ uri );
198204 }
@@ -209,7 +215,7 @@ public function toPsrRequest() {
209215 return new Psr7Request (
210216 $ this ->method ,
211217 $ this ->getUri (),
212- $ this ->headers ->toPsr7Array (),
218+ $ this ->Headers ->toPsr7Array (),
213219 isset ($ this ->body ) ? new Psr7Stream ($ this ->body ) : null
214220 );
215221 }
0 commit comments