Access to request headers on static requests?

48 views
Skip to first unread message

Konstantin Nikiforov

unread,
May 29, 2012, 4:08:48 AM5/29/12
to chica...@googlegroups.com
Hi.

I have a project.
Project has a static file (for example "/static/js/file.js").
For every request for this static file, I need to access http-referrer
header for monitoring reasons.

I can write a controller, who will serve this file. But i don't want to
reimplement chicagoboss 304-caching logic. How to write controller, that
wraps around built-in chicagoboss static-file-serving-logic?
signature.asc

Guido Witmond

unread,
May 29, 2012, 10:17:59 AM5/29/12
to chica...@googlegroups.com
If you need just monitoring without any filtering, I guess you might
use a reverse proxy in front of CB and let the proxy log it.

Otherwise, you could take the file out of the static-directory and write
a controller with a single before_/1 function like:

-module(your_controller, [Req]).
before_(_Action) ->
X:log(Req->get_header(referer).

Regards, Guido Witmond

signature.asc

Konstantin Nikiforov

unread,
May 30, 2012, 2:52:14 AM5/30/12
to chica...@googlegroups.com
Thanks for your response.

Could you please describe the second approach?
That should be return value of before_(_Action) function?
Where to place the static file?
I've created a controller named "myproj_js_controller.erl" and placed
my static file into /src/view/js/file.js.html.
File is rendered like template and no 304 Not modified is returned
automatically.


В Tue, 29 May 2012 16:17:59 +0200
Guido Witmond <gu...@witmond.nl> пишет:
signature.asc

Guido Witmond

unread,
May 31, 2012, 7:08:38 AM5/31/12
to chica...@googlegroups.com
On 30-05-12 08:52, Konstantin Nikiforov wrote:
> Thanks for your response.
>
> Could you please describe the second approach?
> That should be return value of before_(_Action) function?
> Where to place the static file?
> I've created a controller named "myproj_js_controller.erl" and placed
> my static file into /src/view/js/file.js.html.
> File is rendered like template and no 304 Not modified is returned
> automatically.
>
It seems you are right on track. A slightly improved version.

-module(your_controller, [Req]).
before_(_Action) ->
X:log(Req->header(referer), %% log it
ok. %% return ok.

Module X is the one that you create to monitor it. Unless you have very strict real time monitoring requirements in your module X, I believe you're reinventing a web server log.


Cheers, Guido.



signature.asc
Reply all
Reply to author
Forward
0 new messages