Hi,

Here is my improved 'default' script. It now works both on c9.io and on localhost, and it handles both "doc" and "doc/". The logic that takes care of all this, may not be rock solid and very clean, but at the moment it's the best I can do. Here it is:

# This 'default' will be executed as a "script", called from lib/http.l

(let (Localhost (tail (chop "127.0.0.1") (chop *Adr))
        IndexOf "Index of "
        Path (car (file))
        APath Path
        Th '(class . th) )
    (when (tail '("/" "/") (chop Path))
(setq Path (pack (head -1 (chop Path)))) # removing extra "/" at the end
        (setq APath
            (if Localhost
                Path            # need APath on localhost
                "" ) ) )        # no APath needed
    (html NIL
        (pack IndexOf Path (when Localhost " (localhost)"))    # title
        "@lib.css"
        '(style . "margin: 20px 60px; font-size: 105%;")    # body style
        (prin "<style scoped>"
            "tr:not(.th):hover {background-color: #ccf}"
            "</style>" )
        (<h1> NIL IndexOf Path)
        (<table> '(style . "border-collapse: collapse") NIL NIL
(<tr> Th (<th> NIL "Name") (<th> NIL "Last modified") (<th> NIL "Size"))
            (<tr> Th (<th> '(colspan . "3") (<hr>)))
            (chdir Path
                (for F (sort (dir))
(unless (= "default" F) # skipping name of this file
                        (let (Cnt (car (info F))
                                Dat (dat$ (cadr (info F)) "-")
                                Tim (tim$ (cddr (info F))) )
                            (when (=T Cnt) (setq Cnt "-"))    # directory
                            (<tr> NIL
                                (<td> NIL (<href> F (pack APath F)))
                                (<td> '(style . "padding: 0 2em")
(<span> NIL Dat) (<span> '(style . "padding-left: 1em") Tim) ) (<td> '(style . "text-align: right") Cnt)) ) ) ) )
            (<tr> Th (<th> '(colspan . "3") (<hr>))) )
        (<p> '(style . "margin: 0; font: italic small serif;")
(ht:Prin "PicoLisp v" (glue "." (version T)) " (" *OS ") Server") ) ) )

/Jon

On 23-05-13 14:19 , Jon Kleiser wrote:
Hi Alex,

I tried *Host and *Referer from my script, but they were empty. *Adr, however, gave me "::ffff:127.6.26.129", and that can be useful. I think I've also found a workaround for the "doc" / "doc/" effect on the URLs in the list. I'll show it a little later ...

Thanks for the globals!

/Jon

On 23-05-13 13:59 , Alexander Burger wrote:
Hi Jon,

of doc/"). Is it possible for my "default" script to access any info
about the HTTP request from my web server (web.l)?
There are some globals which are set by the server, like

    *Url           The requested URL
    *Adr           The client's address
    *Post          Boolean GET/POST
    *SesId         Session ID
    *ContLen       Content length
    *Http1         0 or 1
    *Host          Host machine
    *Gate          https or not
    *Referer       Referrer
    *Cookies       Assoc-List of cookies
    *Agent         User agent

♪♫ Alex


--
UNSUBSCRIBE: mailto:picolisp@software-lab.de?subject=Unsubscribe

Reply via email to