r.path already has the leading '/'
r.query does not have the necessary '?'
so http://example.com/test.cgi?yay=me
var xb = mpBody.withNewLine() & body.withNewLine()
I don't know about the multipart, but body having a new line appended screws up the server I'm connecting to. dunno if that is a problem with this library or the server.
...
result = request(redirectTo, meth, xh, body, sslContext, timeout, userAgent, proxy)
also, post() handling redirection doesn't account for cookies (which also screws up the server I'm connecting to)
I don't know about the multipart, but body having a new line appended screws up the server I'm connecting to. dunno if that is a problem with this library or the server.
That looks wrong indeed. I never noticed because all my post bodies ended with a newline.
should redirections include the POST parameters again? and if so, shouldn't it be xb intead of body?
Yes, done. Both of these in the new pull request: https://github.com/Araq/Nim/pull/1948/files
also, post() handling redirection doesn't account for cookies (which also screws up the server I'm connecting to)
I'm not sure I understand this. There is no cookie handling at all yet (unfortunately). Does the server tell you to set cookies and we're not doing it automatically or what exactly?
I'm not sure I understand this. There is no cookie handling at all yet (unfortunately). Does the server tell you to set cookies and we're not doing it automatically or what exactly?
First POST request -> Responds with a redirect and a session id cookie. After a couple of redirects, post() returns to my code, with the headers from the last redirected URL - no session cookie. So I don't get the session cookie in my code, and my next request fails.
Probably not able to be handled properly without full-on cookie support. I just use request() instead of post() and handle cookies and redirection myself, for now.
Also, there is a check to see if the redirect is GET or POST, but either way the POST parameters are passed along in the body??
Also, there is a check to see if the redirect is GET or POST, but either way the POST parameters are passed along in the body??
Hm, no idea how this should work properly.
This works for me. Basically, just keep replacing "Cookie:..." in the headers with any "Set-Cookie" that comes along. Also, sets "Set-Cookie" in the returned response to whatever the last cookie was.
The last part of post() ->
- result = request(url, httpPOST, xh, xb, sslContext, timeout, userAgent,
- proxy)
var lastUrl = ""
- for i in 1..maxRedirects:
- if result.status.redirection():
- if result.headers["Set-Cookie"] != "":
var x = find(xh, "\nCookie: ")
if x >= 0: delete(xh, x+1, find(xh, "\n", x+1))
xh.add("Cookie: " & result.headers["Set-Cookie"] & "\c\L")
let redirectTo = getNewLocation(lastURL, result.headers)
var meth = if result.status != "307": httpGet else: httpPost
- result = request(redirectTo, meth, xh, xb, sslContext, timeout,
- userAgent, proxy)
lastUrl = redirectTo
var x = find(xh, "\nCookie: ")
- if x >=0 and result.headers["Set-Cookie"] == "":
- result.headers["Set-Cookie"] = substr(xh, x+10, find(xh, "\n", x+1))
EDIT: layout