11:36:18 <aleksejs_> Is there any way how to distinct ajax and non-ajax requests in routing?
16:45:08 <stepkut> aleksejs_: As far as I know there is nothing about the ajax request itself that uniquely identifies it as such -- what are you trying to accomplish by distinguishing between the two?
16:48:39 <aleksejs_> I know that there is a header HTTP_X_REQUESTED_WITH which will be ==  'xmlhttprequest' if request is done by ajax
16:49:04 <aleksejs_> I used it a couple of times in php
16:51:54 <aleksejs_> aleksejs_> fo example, user requests /foo/bar with ajax, he will get only response as json string, but if he opens url /foo/bar, the whole page will be loaded and then ajax request to /foo/bar will be sent
16:52:07 <aleksejs_> that's why I want to differ them
16:53:49 <stepkut> so you could use getHeaderM to check for that header -- however, it seems like it would be more appropriate to use the Accept header ? http://en.wikipedia.org/wiki/Content_negotiation
16:55:36 <stepkut> either way you use the getHeaderM function to get the header you want to examine
16:58:25 <aleksejs_> may I use it in routing?
17:08:28 <stepkut> of course
17:10:36 <stepkut> there is no explicit routing phase in happstack..
17:31:48 <aleksejs_> What am I doing wrong? http://vpaste.net/dnYil it doesn't accept request "/comment" neigher with nor with that header
17:32:01 <aleksejs_> without*
18:14:08 <stepkut> for starts, the header is actually named, X-Requested-With
18:14:26 <stepkut> HTTP_X_REQUESTED_WITH is just a PHP variable based on the header name
18:15:57 <stepkut> if it does not accept it with out the header -- then perhaps your request is not what you think it is
18:18:02 <aleksejs_> here are headers for the request
18:18:03 <aleksejs_> http://vpaste.net/1YGG1
18:18:27 <aleksejs_> I set that header manually
18:19:07 <aleksejs_> I replaced it in code with X-Requested-With, no difference
18:20:29 <stepkut> are you sure that the request is being made to /comment, that it is a POST request, and that the POST body is the format expected by withData ?
18:21:05 <aleksejs_> I believe getHeaderM should return Maybe "X-Requested-With" if it is set
18:22:15 <stepkut> it should return, Just "xmlhttprequest", in your case
18:23:09 <stepkut> what happens when you make the request? You get a 404 ?
18:24:24 <aleksejs_> yes
18:24:39 <aleksejs_> and I tried getHeaderM "Host", same result
18:24:49 <stepkut> indeed
18:25:12 <stepkut> getHeaderM just tries to fetch the header -- but it doesn't not matter if it matches or not
18:25:36 <aleksejs_> should it return Nothing if it's not set
18:25:39 <aleksejs_> ?
18:25:41 <stepkut> yes
18:26:01 <aleksejs_> so why doesn't it work?
18:26:35 <stepkut> there are three things which could call mzero: dir "comment", method POST, or withData
18:26:46 <stepkut> one of those parts is not finding what it excepts
18:26:49 <stepkut> expects
18:27:05 <aleksejs_> if I remove that getHeaderM part, it workd
18:27:08 <aleksejs_> s*
18:28:38 <stepkut> seems unlikely
18:29:29 <aleksejs_> I can proove
18:30:21 <stepkut> I'd like to see that
18:30:35 <aleksejs_> 1 minute
18:33:31 <stepkut> http://lpaste.net/99217
18:33:56 <stepkut> that paste demonstrates that it does not matter if the header is found, and also shows how to dump the Request
18:34:04 <stepkut> though it won't show the request body
18:39:45 <aleksejs_> hmm
18:40:26 <aleksejs_> if I do it via curl, everything works
18:40:43 <aleksejs_> but when i do it via ajax, it doesn't
18:40:46 <stepkut> so it is probably an error in the client side code?
18:41:10 <aleksejs_> I'm doing it through browser's console
18:41:37 <stepkut> well.. you're doing it wrong?
18:41:56 <aleksejs_> x = new XMLHttpRequest; x.open('POST', "comment"); x.send("post=1&text=asdfqwer")l
18:42:04 <aleksejs_> what's whong here?
18:42:15 <aleksejs_> ignore that l
18:43:18 <aleksejs_> curl:
18:43:19 <aleksejs_> curl --data "post=1&text=asdfqwer" http://localhost/comment
18:44:16 <aleksejs_> I fail to see the difference
18:44:28 <aleksejs_> or wait...
18:45:40 <aleksejs_> x.setRequestHeader("Content-type","application/x-www-form-urlencoded"); << this should be done before sending post request :)
18:45:49 <aleksejs_> in browser
18:46:07 <stepkut> :)
18:47:11 <aleksejs_> ok, I'll try it now with header check
18:48:34 <aleksejs_> yes, it works exactly as it should :)
18:48:48 <stepkut> :)
18:49:14 <stepkut> so, you added code to actually examine the value returned by getHeaderM?
18:49:39 <aleksejs_> no, I haven't, I just check if it is set
18:49:59 <stepkut> you check that it is Just vs Nothing?
18:50:17 <aleksejs_> msum does it,I believe
18:50:29 <stepkut> what I mean is --  calling getHeaderM by itself doesn't actually check anything
18:50:30 <aleksejs_> the code is as I posted before
18:50:52 <stepkut> it gets the header if it exists.. but it is up to you to do something with the value that is returned
18:51:37 <aleksejs_> yes
18:51:45 <aleksejs_> but it's enough for now
18:52:12 <stepkut> in the code as you posted before.. the getHeaderM line served absolutely no purpose..
18:52:26 <aleksejs_> it will
18:52:42 <stepkut> k
18:52:46 <aleksejs_> because I have another question for you :)
18:53:10 <aleksejs_> I need to modify routes this way:
18:54:53 <aleksejs_> for now, it matches requests (and headers), and if it doesnt, it searches for content in /ctatic
18:54:58 <aleksejs_> static
18:56:09 <aleksejs_> I need to add some rule that would silently redirect (without changing link) to index.html if it fails match any route and if it fails to find a content in static
18:56:20 <aleksejs_> basically, i need to override 404
18:56:47 <stepkut> just add a rule at the end: , seeOther "/index.html" (toResponse ())
18:58:37 <aleksejs_> it works, but it's not a silent redirect :(
18:58:46 <stepkut> ??
18:59:25 <aleksejs_> it changes link
18:59:51 <stepkut> you want it to show the index.html regardless of what the link says?
19:00:02 <aleksejs_> exactly
19:00:34 <stepkut> seems like asking for trouble to me but, serveFile (asContentType "text/html") "static/index.html"
19:01:18 <stepkut> any assets (.css, .jpg, etc) in that file will need to have absolute URLs not relative -- since you have no idea what the actual URL is going to be you can't be relative to it..
19:01:42 <aleksejs_> I know
19:02:02 <aleksejs_> but it's ok, I always use absolute url for static content
19:03:41 <aleksejs_> the idea is when user lands to host/blah, it will be redirected to index.html, and JS will extract window.location.pathname and will build a page using a content from /blah
19:09:11 <aleksejs_> actually I feel stupid now: I spent 3 hours just because I forgot to set that header, but happpstack worked just fine
19:09:48 <stepkut> Sounds like web development :)
19:10:08 <aleksejs_> well, I am web developer :)