chicken-users
[Top][All Lists]
Advanced

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

Re: I'm starting using chicken4 (Re: [Chicken-users] 4.6.1 performance b


From: Peter Bex
Subject: Re: I'm starting using chicken4 (Re: [Chicken-users] 4.6.1 performance boost
Date: Fri, 1 Oct 2010 20:10:36 +0200
User-agent: Mutt/1.4.2.3i

On Sat, Oct 02, 2010 at 12:22:22AM +0900, Daishi Kato wrote:
> > Yes, this is uglier.  There are several different request handling
> > eggs now though!  They make it easier to handle incoming requests.
> 
> Is it that ugly?
> None of the request handling eggs in the spiffy manual
> was not so low level.

I'm confused; do you think the eggs are lower-level than your code, or
do you think the spiffy code itself is low-level, or what?

> I don't understand the discussion here. How felix isn't happy?

He's unhappy that the way to define request handlers has become so
much more complicated.

> I thought the vhost support is very powerful.

It is, but it comes at the price of not being able to simply define
request handlers at the global path level, since those would apply
to all vhosts.

> > > There were many tiny things for porting my code, such as dealing
> > > with the fancy uri-common egg and string-match -> string-search.
> > 
> > Are you using "fancy" in a good way or in a bad way?  I'm really eager
> > to hear how these new http libraries are being used and how people like
> > them, so I can improve where things are not as smooth as they should be.
> 
> Good question. I used "fancy" in a good way, but if you ask me:
> it might be too premitive, or there are too many procedures to understand.

URI-common exports 30 identifiers, I guess you could call that a lot :)
However, most of those are simply record accessors and constructors.
There are a bunch of predicates and conversion procedures which are
sorely needed.

If you have more specific questions about the various procedures, feel
free to ask them.  Maybe you can help me out improving the documentation,
to make it easier for other people and ensure they won't run into the
same problems you have.

> My code was (since it was from chicken3) based on the string-based
> representation of URLs, hence I made some util functions as follows:
> 
> (define (get-path-from-uri uri)
>   (define len (- (string-length prefix) 1))
>   (let ([path (string-intersperse (cdr (uri-path uri)) "/")])
>     (and path
>          (string-prefix? prefix path)
>          (string-drop path len))))

What's "prefix" here?  It seems like an undefined variable.
If it's some directory which you want to strip from the path, you
can use matchable (or do manual cons/car/cdring):

(match (uri-path uri)
  (('/ "my" "prefix" . rest) (string-intersperse rest "/")) ;; Remove /my/prefix
  (else #f))

You can also construct the base URI and generate a relative reference
using uri-relative-from, but then you have to be careful when the string
is not a proper prefix (which you can verify by checking the first
element for not being '/ or "..").

> (define (get-ref-url-from uri)
>   (let ([baseuri (uri-reference (sprintf "~a://~a:~a/" (uri-scheme uri) 
> (uri-host uri) (uri-port uri)))])
>     (uri->string (uri-relative-from uri baseuri))))

I'm not sure what the purpose of this one is, but you could do it
with either

  (uri->string (update-uri uri scheme: #f host: #f))

or

  (uri->string
    (uri-relative-from uri (update-uri uri path: #f query: #f fragment: #f)))

I think it would make more sense to take a look at your code and see
why you need to do this.  It rarely makes sense to convert an absolute
URI to a relative one like this, I think.

> (define (get-query-from-uri uri)
>   (let ([query (uri-query uri)])
>     (and (pair? query)
>          (map (lambda (x) (cons (symbol->string (car x)) (cdr x)))
>               query))))

Things like this can be done easily by creating an "empty" uri reference
and copying over those things you need:

(uri->string (update-uri (uri-reference "") query: (uri-query uri)))

> Please let me know if there's a better way of doing it.

I hope you like these examples.  If I missed something or if there's
a cleaner way to do one of these, I'm sure people will correct me :)

Cheers,
Peter
-- 
http://sjamaan.ath.cx
--
"The process of preparing programs for a digital computer
 is especially attractive, not only because it can be economically
 and scientifically rewarding, but also because it can be an aesthetic
 experience much like composing poetry or music."
                                                        -- Donald Knuth



reply via email to

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