get-url of empty content fails (fixed in 10.6.4)

Q&A's, tips, howto's
Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: get-url of empty content fails

Post by Lutz »

Trying to accomodate your observations but maintaining compatibility with earlier versions:

Not in list mode:
As in earlier versions delete/get/put/post -url always return a string. This string is either the content returned by the server or an error string starting with "ERR: " followed either by a newLISP error message or followed by a HTTP server response string, which also contains the HTTP error code. Followed by content from the server if available.

In list mode:
The first list member is the server header, second member is the original server content or an empty string and the third member is the HTTP server response string, which also contains the HTTP error code. This ways list mode is more consistent than before. The second list member always is the original server content it never has error info prepended. HTTP response line is always the third member. The server HTTP code can be parsed out easily:

Code: Select all

((parse http-response " ") 2) ;=> response code
http://www.newlisp.org/downloads/develo ... nprogress/

ps: manual update later

hartrock
Posts: 136
Joined: Wed Aug 07, 2013 9:37 pm

2. Update: suggestion (removed errorneous "fix")

Post by hartrock »

2. Update: suggestion (removed errorneous "fix")

What about putting the int status code (or nil, if there is an invalid HTTP status line) as fourth member after the HTTP server response string in "list" mode?
Or is there any problem with this idea, I don't see?

There already is HTTP status as an int in nl-web.c, so parsing it from outside seems to be unneeded. If someone wants to get exact status line - e.g. for checking HTTP version - it is there after your proposal: then parsing it is the way to go.

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Re: get-url of empty content fails

Post by Lutz »

check out: http://www.newlisp.org/downloads/develo ... nprogress/ 2015-07-24 02:12

now always four members in list mode: header, content, http response line, status code

hartrock
Posts: 136
Joined: Wed Aug 07, 2013 9:37 pm

Re: get-url of empty content fails

Post by hartrock »

Lutz wrote:check out: http://www.newlisp.org/downloads/develo ... nprogress/ 2015-07-24 02:12

now always four members in list mode: header, content, http response line, status code
Thank you!
Result now seems to be a good compromise between:
  • effort and improvement, and
  • different error handling purposes.
PS: one test has to be updated:

Code: Select all

sr@free:/tmp/newlisp-10.6.4/qa-specific-tests$ diff qa-net_orig qa-net
88c88
< (if (find "server code 404:" (get-url (string "http://" host ":" port "/xyz.xyz")))
---
> (if (find "ERR: HTTP/1.0 404 File or Directory not found" (get-url (string "http://" host ":" port "/xyz.xyz")))

Locked