guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: (web server): Trying to define a predicate »re quest-included-in-nav


From: Mark H Weaver
Subject: Re: (web server): Trying to define a predicate »re quest-included-in-nav-bar?«
Date: Sun, 23 Sep 2012 14:32:58 -0400
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.1 (gnu/linux)

"Dr. Ludwig Meier" <address@hidden> writes:
> I would like to extend the example given in section 7.3.10.2 of the
> guile-manual. I am trying to write a web handler procedure which shall
> inspect whether or not a request can be found in a list that
> represents items of a navigation bar.

[...]

> (define (request-path-components request)
>   (split-and-decode-uri-path (uri-path (request-uri request))))
>
> (define (request-included-in-nav-bar? request)
>   (if (member (car (request-path-components request))
>             *navigation*)
>       #t #f))

Here, and in multiple other places, you evaluate:

  (car (request-path-components request))

which will raise an exception unless there is at least one non-empty
path component.  Somehow you need to cope with the possibility of an
empty path, e.g.:

  (define (request-included-in-nav-bar? request)
    (let ((components (request-path-components request)))
      (and (pair? components)
           (member (car components) *navigation*)
           #t)))

> Starting the web-server and pointing the browser to
> localhost:8080/start yields an error:
>
> ------
>
> scheme@(guile-user)> (run-server homepage)
> <unnamed port>:36:14: In procedure request-included-in-nav-bar?:
> <unnamed port>:36:14: In procedure car: Wrong type argument in
> position 1 (expecting pair): ()

[...]

> While working fine above, my predicate »request-included-in-nav-bar?«
> now breaks: The expression (request-path-components request) seems to
> evaluate to anything but ("start").  What am I doing wrong?

In this case, (request-path-components request) returned the empty list,
which implies that the URI path contains no non-empty path components.
This suggests that perhaps "http://localhost:8080/"; was requested for
some reason.

Even if you don't expect such requests, I recommend that you fix your
code to properly handle them.  Modern web browsers typically generate
additional requests that the user did not ask for.  For example, they
will typically request the "favicon" for display beside the URL in the
navigation bar.

You might also want to add some debugging output to your program that
shows what URLs are being requested.  If you suspect that Guile's web
server is doing something wrong, then you could try using a simpler web
browser such as "lynx" or "w3m", or even telnetting directly to port
8080 and performing the HTTP request manually.

    Mark



reply via email to

[Prev in Thread] Current Thread [Next in Thread]