trying to interact via ajax requests, sessions stored via cookies are a pain #7

Closed
hiredman opened this Issue Jul 5, 2012 · 7 comments

Projects

None yet

4 participants

@hiredman
hiredman commented Jul 5, 2012

I am trying to write a client (I guess? kovasb/session#3) in clojurescript, I could be going about this all wrong, it looks like it is close to impossible to get access to the cookies from an ajax request and pass them around properly, it also is not clear to me why session data is stored as a cookie some how and a "session" key is in all the maps passed around

@hiredman
hiredman commented Jul 5, 2012

I was able to work around the issue I had (maybe just my own ignorance regarding cookies and jquery) replacing ring's cookie based session store with something else:

hiredman/session@feeb31d

@cemerick
Owner
cemerick commented Jul 5, 2012

I think the sessions you're talking about are the nREPL session id's, which have nothing to do with HTTP sessions. (See the TODO section in https://github.com/cemerick/drawbridge.) What you want to be doing is issuing the same messages that a non-HTTP nREPL client would send in order to retain/clone sessions as desired.

@hiredman
hiredman commented Jul 5, 2012

what I find is, unless I retain the http session I lose the results of long running commands. and I was not able to find an easy way to maintain the http session with the ring session middleware using an ajax http request. As soon as I hacked in a non-cookie based session layer, it started working. I am completely ignoring the nrepl "session" thing currently.

@hiredman
hiredman commented Jul 5, 2012

this isn't an issue saying that anything is wrong, it just seems like wiring up ajax requests to drawbridge isn't very nice. it is possible that I shouldn't be using the default handler, maybe I should be using something more stripped down.

@sritchie
sritchie commented Jan 3, 2015

hmm, this is odd, since ajax requests do in fact set cookies when they receive a Set-Cookie header.

@upgradingdave

(I see this is a really old issue, so if please feel free to ignore if this isn't relevant).

I've been playing around with drawbridge today, my goal is to dig deeper into understanding how nrepl works. I've got it so that I can send clojure forms from a Ace Javascript Editor running in a browser to a nrepl session via drawbridge compojure /repl route.

At first, I thought I was running into this same issue. But then, by tracking the state, such as tracking which message id's have received a "done" status, I think I have it working pretty well. But I'm worried I might be missing something.

I was wondering if you'd mind taking a look and let me know if I'm thinking about this correctly?

I have it working like this:

  • First, get a new session by sending POST {:id 1 :op "clone"}
  • I get an empty response body from the post:
[]
  • Then I continue to send GET requests until I get a "done" status. I match the message id with the original POST request to know when the command is complete:
[
{"id":"1","session":"929e9f0b-dd1c-4281-9662-472fcb26a817","new-session":"85a64aeb-8667-49ab8b99-3b12d888c9cf","status":["done"]}
]
  • Now that I have a nrepl session, I use that to POST messages with unique id's such as {:id 2 :op "eval" :code "(str "Hi")"}`
[
{"id":"2","session":"85a64aeb-8667-49ab-8b99-3b12d888c9cf","value":"\"Hello World!\"","ns":"user"},
{"id":"2","session":"85a64aeb-8667-49ab-8b99-3b12d888c9cf","status":["done"]}
]

Is that the correct way to interact with nrepl? All the ajax requests appear to be sharing the same ring-session cookie, but I think that's ok, right?

Am I using this as it was intended or am I totally lost?! I'm just starting to scratch the surface of nrepl and so not sure if I'm thinking about this correctly.

Thanks for your help.

@cemerick
Owner

Yup, that looks reasonable. Note that drawbridge is one very peculiar nREPL transport implementation (HTTP isn't exactly the most friendly thing in the world). Depending on your context, a websocket nREPL transport might be easier/simpler, and would not be difficult to build.

@cemerick cemerick closed this Jul 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment