112 } |
113 } |
113 if ( isset( $parsed_url['host'] ) ) { |
114 if ( isset( $parsed_url['host'] ) ) { |
114 $this->domain = $parsed_url['host']; |
115 $this->domain = $parsed_url['host']; |
115 } |
116 } |
116 $this->path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '/'; |
117 $this->path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : '/'; |
117 if ( '/' !== substr( $this->path, -1 ) ) { |
118 if ( ! str_ends_with( $this->path, '/' ) ) { |
118 $this->path = dirname( $this->path ) . '/'; |
119 $this->path = dirname( $this->path ) . '/'; |
119 } |
120 } |
120 |
121 |
121 if ( is_string( $data ) ) { |
122 if ( is_string( $data ) ) { |
122 // Assume it's a header string direct from a previous request. |
123 // Assume it's a header string direct from a previous request. |
133 |
134 |
134 // Set everything else as a property. |
135 // Set everything else as a property. |
135 foreach ( $pairs as $pair ) { |
136 foreach ( $pairs as $pair ) { |
136 $pair = rtrim( $pair ); |
137 $pair = rtrim( $pair ); |
137 |
138 |
138 // Handle the cookie ending in ; which results in a empty final pair. |
139 // Handle the cookie ending in ; which results in an empty final pair. |
139 if ( empty( $pair ) ) { |
140 if ( empty( $pair ) ) { |
140 continue; |
141 continue; |
141 } |
142 } |
142 |
143 |
143 list( $key, $val ) = strpos( $pair, '=' ) ? explode( '=', $pair ) : array( $pair, '' ); |
144 list( $key, $val ) = strpos( $pair, '=' ) ? explode( '=', $pair ) : array( $pair, '' ); |
199 if ( false === stripos( $domain, '.' ) ) { |
200 if ( false === stripos( $domain, '.' ) ) { |
200 $domain .= '.local'; |
201 $domain .= '.local'; |
201 } |
202 } |
202 |
203 |
203 // Host - very basic check that the request URL ends with the domain restriction (minus leading dot). |
204 // Host - very basic check that the request URL ends with the domain restriction (minus leading dot). |
204 $domain = ( '.' === substr( $domain, 0, 1 ) ) ? substr( $domain, 1 ) : $domain; |
205 $domain = ( str_starts_with( $domain, '.' ) ) ? substr( $domain, 1 ) : $domain; |
205 if ( substr( $url['host'], -strlen( $domain ) ) !== $domain ) { |
206 if ( ! str_ends_with( $url['host'], $domain ) ) { |
206 return false; |
207 return false; |
207 } |
208 } |
208 |
209 |
209 // Port - supports "port-lists" in the format: "80,8000,8080". |
210 // Port - supports "port-lists" in the format: "80,8000,8080". |
210 if ( ! empty( $port ) && ! in_array( $url['port'], array_map( 'intval', explode( ',', $port ) ), true ) ) { |
211 if ( ! empty( $port ) && ! in_array( $url['port'], array_map( 'intval', explode( ',', $port ) ), true ) ) { |
211 return false; |
212 return false; |
212 } |
213 } |
213 |
214 |
214 // Path - request path must start with path restriction. |
215 // Path - request path must start with path restriction. |
215 if ( substr( $url['path'], 0, strlen( $path ) ) !== $path ) { |
216 if ( ! str_starts_with( $url['path'], $path ) ) { |
216 return false; |
217 return false; |
217 } |
218 } |
218 |
219 |
219 return true; |
220 return true; |
220 } |
221 } |