webserver example

111 prikaza
Preskoči na prvu nepročitanu poruku

edward sillador

nepročitano,
22. ožu 2015. 23:34:2422. 03. 2015.
u land-o...@googlegroups.com
I tried the solution from the following links to make the web server work but unfortunately it still does not work.

https://groups.google.com/forum/#!searchin/land-of-lisp/server/land-of-lisp/afwjs0eic94/nnnoJiVDkYAJ
https://groups.google.com/forum/?fromgroups=#!topic/land-of-lisp/Ei_Cragfbp0

Here is my modified version of hello-request-handler:
(defun hello-request-handler (path header params)
  (if (equal path "greeting")
      (let ((name (assoc 'name params)))
        (if (not name)
            (progn
              (princ "HTTP/1.1 200 OK~a")
              (princ "<html><form>What is your name?<input name='name' /> </form></html>"))
          (format t "<html>Nice to meet you, ~a!</html>" (cdr name))))
    (princ "Sorry... I don't know that page.")))

Could someone help me?

Thank you.

Simon Nicolussi

nepročitano,
30. ožu 2015. 18:05:0730. 03. 2015.
u land-o...@googlegroups.com
Edward Sillador modified the hello-request-handler function:
> (if (not name)
> (progn
> (princ "HTTP/1.1 200 OK~a")
> (princ "<html><form>What is your name?<input name='name' />
> </form></html>"))
> (format t "<html>Nice to meet you, ~a!</html>" (cdr name))))

The hello-request-handler function writes to standard output, so you can
call it in the REPL to see whether its output matches your expectations:
> CL-USER> (hello-request-handler "greeting" nil nil)
> HTTP/1.1 200 OK~a<html><form>What is your name?<input name='name' /></form></html>

It probably doesn't, but it's unclear what exactly you expected. Control
sequences like ~a only take on a special meaning in control strings, the
second argument to the format function. Your function call, however, has
no value argument either (which is understandable, as princ would fail).

An HTTP status line has to end in CRLF (carriage return plus line feed),
followed by a header section (which is empty here), followed by an empty
line (another CRLF), followed by a message body (an HTML document). But
the book mentions that modern web browsers are forgiving; they accept a
single LF for EOL (as they're entitled to, according to RFC 7230, 3.5),
which means that ~% suffices as the line terminator on any of the major
operating systems. This leaves us with a function like the following:

(defun hello-request-handler (path header params)
(if (equal path "greeting")
(let ((name (assoc 'name params)))
(format t "HTTP/1.0 200 OK~2%")
(if (not name)
(princ "<html><form>What is your name?<input name='name' />
</form></html>")
(format t "<html>Nice to meet you, ~a!</html>" (cdr name))))
(princ "Sorry... I don't know that page.")))

As you can see, I moved the status line so that it precedes either HTML
document. Tested with Internet Explorer, Firefox, Chrome, Safari, Opera.

--
Simon Nicolussi <si...@sinic.name>
http{s,}://{www.,}sinic.name/
Odgovori svima
Odgovori autoru
Proslijedi
0 novih poruka