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

?

+3


source to share


6 answers


Can the is_initial () method of the request object be used? Using this method, you can determine if a request is a subordinate request.



Kohana 3.2 API, Request - is_initial ()

+1


source


It looks like you could easily fix this problem by setting some kind of static variable that your application can check. If he is not FALSE, then you know his inner.



+1


source


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;
    }

}

      

+1


source


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.

+1


source


You may be looking for a method is_external

:
http://kohanaframework.org/3.2/guide/api/Request#is_external

0


source


Kohana 3.3 in controller:

$this->request->is_initial()

      

http://kohanaframework.org/3.3/guide-api/Request#is_initial

0


source







All Articles