How do you know if Kohana's request is internal?
I am writing an API using Kohana. Every external request must be signed by the client for acceptance.
However, I also need to make internal requests by creating the object Request
and the caller execute()
. In these cases, the signature is not needed because I know the request is secure. So I need to know that the request was internal so that I can skip signature verification.
So, is there a way to find out if the request was manually created using an object Request
?
source to share
This is how I did it: I overridden the object Request
and added a property to it is_server_side
. Now, when I create a request, I just set it up so that I know it was generated on the server side:
$request = Request::factory($url);
$request->is_server_side(true);
$response = $request->execute();
Then in the controller receiving the request:
if ($this->request->is_server_side()) {
// Skip signature check
} else {
// Do signature check
}
And here is the overridden requests class in the app /classes/request.php :
<?php defined('SYSPATH') or die('No direct script access.');
class Request extends Kohana_Request {
protected $is_server_side_ = false;
public function is_server_side($v = null) {
if ($v === null) return $this->is_server_side_;
$this->is_server_side_ = $v;
}
}
source to share
Looking at the Request, it looks like your new request will be considered an internal request, but does not contain any special flags it sets to tell about it. Look at 782-832 in Kohana_Request ... nothing will help you.
With this, I would suggest extending Kohana_Request_Internal to add a flag that shows it as internal and pulls it in your application when you need to check if it is internal / all others.
source to share
You may be looking for a method is_external
:
http://kohanaframework.org/3.2/guide/api/Request#is_external
source to share