The web in a box - a next generation web framework for the Perl programming language

IRC log for #mojo, 2017-02-02

| Channels | #mojo index | Today | | Search | Google Search | Plain-Text | summary

All times shown according to UTC.

Time Nick Message
00:00 jberger I think I might start by making a cors helper
00:00 jberger which validates the request origin however you want to do that
00:00 jberger sets the response headers
00:00 jberger and then returns a boolean of if it is allowed
00:01 jberger after you have that then you just have to wire it up to your requests somehow
00:01 jberger but at least it contains the logic of the cors stuff
00:03 mswayne Given said helper, how do I apply it to static files?
00:03 jberger ugh, static files
00:03 jberger yeah, you need a hook, early on
00:04 jberger and that's why that plugin isn't working for you
00:04 jberger I just started playing around with the plugin myself to try to get to understand it
00:04 mswayne Uh oh.  I need to make this crap work from a plugin.
00:04 jberger because the more I was thinking about it the more I understood the choices it was making
00:05 jberger plugins can set hooks
00:05 jberger no worries
00:05 mswayne Whew.
00:05 jberger in fact, SecureCORS does use one, just one that doesn't help with static files
00:06 mswayne after_render.
00:06 jberger http://mojolicious.org/perldoc/Mojolicious#HOOKS
00:07 mswayne So, if I add an "after_static" hook to SecureCORS, would that maybe cause it to work?
00:07 jberger depending on how much you want the hook to control, you can try to handle everything in something early like before_dispatch
00:08 jberger hmmmm, I was going to suggest after_static for static files, but that's kinda too late, unless you'd then clear out the static response if a request failed CORS
00:09 pink_mist can you clear out the response in an after_static?
00:09 jberger I don't know, I'd have to try it ;-P
00:11 jberger the too-simple plugin does use it in the before_dispatch hook
00:12 jberger can you kill the request from before_dispatch I wonder
00:16 jberger I actually have an old app that does kill a request in after_static
00:16 jberger I just don't know if it works all that well
00:16 * jberger tests
00:19 jberger no, the mechanism I used there isn't very nice
00:20 sugar joined #mojo
00:24 jberger mswayne: https://gist.github.com/jberger/0bcfa64392078959f20b6a7e2fbdb8fd
00:24 jberger this is the simplest way I can think of to deny a static file, in this case when checking for a header like X-OK being a true value
00:25 jberger so you can check by running:
00:25 jberger perl test.pl get -H X-OK:1 -v /index.txt
00:25 jberger and then again without the header
00:28 jberger does that make any sense?
00:33 mswayne I think so
00:33 mswayne The header test is there to make it easy to test.  However in real code I'd use my cors criteria to decide.
00:41 mswayne its the rendered(400) that causes the static file to be blocked.
00:42 mswayne Ah and the new content object is set to make it so the 400 response is rendered correctly.
00:42 mswayne Thanks.
00:47 jberger close enough
00:48 jberger without replacing the content object the file would be served anyway but with a status of 400
00:48 jberger this down into the lower level stuff than I like to get
00:48 jberger (at least for code like this)
00:49 aborazmeh joined #mojo
00:49 mswayne I've done a couple small projects with mojolicious and never needed to get anywhere near this far into the weeds.
01:21 jberger well again, that plugin is trying to make something per-route via route-default stash variables in a way that isn't commonly done
01:21 jberger but yeah, I don't know if we have any great way of preventing a static file from being served
01:21 marty joined #mojo
01:38 mswayne @jberger Thanks to your help, I was able to make things work with my demo app.  Tomorrow I'll implement it in my real plugin/application morass.
01:39 mswayne jberger
01:40 mswayne The gist I posted earlier now has some working, but simple, code.
01:46 tchaves joined #mojo
03:37 noganex_ joined #mojo
03:52 lluad joined #mojo
03:53 batman sri: I'm on vacation
05:04 dboehmer joined #mojo
05:31 batman kwa: ^^^ (also, you should probably move the comment to #swagger)
05:39 inokenty-w joined #mojo
06:36 dod joined #mojo
06:41 dod joined #mojo
06:50 disputin joined #mojo
07:07 sdeseille joined #mojo
07:15 Vandal joined #mojo
07:49 dod joined #mojo
08:10 AndrewIsh joined #mojo
08:11 sdeseille hello
08:11 purl que tal, sdeseille.
08:20 trone joined #mojo
09:00 foursixnine sri, nope :( Was taking a look to other stuff... but i think i need to implement my own import method
09:07 Petru joined #mojo
09:36 kirby joined #mojo
09:47 sugar joined #mojo
09:48 kwa batman: Moved it to
09:48 kwa #swagger - happy holidays!
10:17 sugar joined #mojo
10:18 marcus kwanzaa?
10:18 purl rumour has it kwanzaa is already over
10:33 Petru joined #mojo
10:51 Petru joined #mojo
11:24 tchaves joined #mojo
11:31 romel joined #mojo
12:04 dotan_convos joined #mojo
12:47 kwa marcus: me?
12:47 purl you are using a single route ($r->any('/:controller/:name')->to(action => 'index');) for your controllers. I'm also using render to automatically pick up the template (so /messages/someusername renders /messages/index.html.ep). This means that all the templates I have open all have the same name - index. Not a massive deal, but I'd prefer it if I could do the equivalent of: $r->any('/:controller/:na
12:49 kwa jberger++ # introducing me to jq
13:02 Petru joined #mojo
13:06 dikim joined #mojo
13:23 marcus kwa: Are you an african holiday?
13:29 kwa haha, no.Just kwakwa (or kwakwaversal) (or kwakwakwakwakwakwakwa)
13:30 kwa (My name doesn't echo when you shout it into a canyon.)
13:34 rshadow joined #mojo
14:08 rshadow joined #mojo
14:16 blonewolfs joined #mojo
14:26 Pyritic joined #mojo
15:03 mcsnolte joined #mojo
15:12 dikim joined #mojo
15:14 polettix joined #mojo
15:17 gryphon joined #mojo
15:39 lluad joined #mojo
15:54 marty joined #mojo
16:04 ashimema joined #mojo
16:09 asarch joined #mojo
16:20 rshadow joined #mojo
16:27 disputin joined #mojo
17:39 dod joined #mojo
17:40 dod joined #mojo
17:58 dod joined #mojo
18:01 PryMar56 joined #mojo
18:05 Petru joined #mojo
18:19 tchaves joined #mojo
18:36 rshadow joined #mojo
19:04 lluad joined #mojo
19:27 sri anyone made a mojolicious syntax extension for vs code yet?
19:28 sri the latest release announcement is really impressive... i feel like i should try it
19:28 sri https://code.visualstudio.com/updates/v1_9
19:32 litwol *gasp*. not using vim ?
19:35 sri vim is always my secondary editor, but i mainly use atom
19:41 genio same here
19:42 genio sri: I don't think anyone made one.  The last conversation made it seem like your old plugin was of the proper type (maybe you can release that with minimal effort)?
19:53 rshadow joined #mojo
20:00 rshadow joined #mojo
20:46 lluad joined #mojo
21:28 dikim joined #mojo
21:36 dod joined #mojo
21:42 tchaves joined #mojo
21:52 zivester joined #mojo
21:52 disputin joined #mojo
21:53 Peppard joined #mojo
22:44 mishanti1 Anyone here using redis as primary datastore in projects, and have though about strategies for doing operations like schema-ish migrations?
22:46 Grinnz i think you'd need to use some combination of MULTI and WATCH
22:46 Grinnz and do one big transaction of generated reads and writes
22:47 Grinnz well the reads would be beforehand, which is what WATCH is for
22:48 mishanti1 Right, and some sane method of rolling back th already executed parts of a MULTI-block if failing some ways into it?
22:48 mishanti1 That is the issue I am most concerned about, and not really sure how to do yet.
22:49 Grinnz MULTI automatically rolls back if either a part of it fails or a WATCHed key has changed
22:50 Grinnz MULTI essentially queues up commands, they are all run atomically on EXEC
22:50 Grinnz if any WATCHed key has changed before it starts, it aborts; if any part of the statement fails, it aborts
22:50 Grinnz it's super useful
22:51 Grinnz so in that sense, there is never any part that is executed, it's all or nothing
22:51 mishanti1 I've been told on two accounts before that that is not always the case, however when I now read the docs than it seems you are absolutely correct. Might have been an issue in an earlier version.
22:51 mishanti1 s/than/then/
22:53 mishanti1 This statement in the docs make me a little hesitant:
22:53 mishanti1 "Errors happening after EXEC instead are not handled in a special way: all the other commands will be executed even if some command fails during the transaction."
22:55 Grinnz as it says later, that can only occur if e.g. you use an operation against a key of the wrong type
22:55 Grinnz definitely something to keep in mind though
22:55 mishanti1 Yeah, need to keep that in mind.
22:56 mishanti1 So the docs seem to be pretty clear on there being no automatic rollback, but if I keep state in the client doing the migration then that could be cobbled together easily enough.
22:57 Grinnz that's also far less important than for a relational database though
22:58 mishanti1 Indeed.
22:58 Grinnz because commands can't randomly fail, and the transaction is presented as a single write, so it can't partly have a connection error or anything
22:59 Grinnz if your code bails out anytime before the actual EXEC, nothing will have run
23:01 mishanti1 Thank you for the input. :) Did clear up some confusion I had.
23:01 mishanti1 I think i'll have another proper read-through of the MULTI/WATCH/EXEC docs when I am rested.
23:04 marty_ joined #mojo
23:05 Grinnz also, https://redis.io/commands/eval may be useful as an alternative, you can just write lua code that is run atomically
23:06 Grinnz i've considered using it, but Mojo::Redis2 doesn't support it
23:08 Petru joined #mojo
23:12 marty joined #mojo
23:15 marty joined #mojo
23:31 sword_smith joined #mojo
23:39 tchaves joined #mojo
23:40 tchaves1 joined #mojo
23:49 marty joined #mojo

| Channels | #mojo index | Today | | Search | Google Search | Plain-Text | summary