[racket] What controls the web-server continuation URL?

From: Jay McCarthy (jay.mccarthy at gmail.com)
Date: Mon Jan 17 10:23:26 EST 2011

Hi Norman,

Whatever URL the servlet is initiated with is used as the base URL for
all subsequent continuations. So, if you contact the servlet at URL
/a/b/c then it will append the continuation tokens to /a/b/c. Since
you have set the servlet-regexp to #rx"", you are free to contact it
with any URL you want. So you could set up your proxy to redirect to
"podcasting/user" rather than just "user".

If from within a servlet, you want to adjust the URL, you can just
copy the ids from the url produced by send/* and change the base.
Here's a little example:

#lang racket
(require rackunit
(require/expose web-server/servlet/web (embed-ids))

(define (copy-ks old-u new-u)
  (embed-ids (continuation-url? (string->url old-u)) (string->url new-u)))

(copy-ks (embed-ids (list 1 2 3) (string->url "http://localhost/user"))

I use the functions the web server really uses, but you could also
just use string manipulation.

If you are okay using undocumented things, you could also parameterize
the current-execution-context and give it a new HTTP request that
contains a different base URI.


2011/1/16 Norman Gray <norman at astro.gla.ac.uk>:
> Greetings.
> What controls the continuation URL generated when using the Racket web server?
> I'm using send/formlet to present and process a form.  The form is presented on a page called http://localhost:8000/user, and when it's submitted, it goes to a continuation page .../user;blah.
> That works fine on http://localhost:8000/user.  But on the deployment machine, the server in question is behind a proxy, so that the actual public URL is http://example.edu/podcasting/user.  In this case, the continuation URL generated is just http://example.edu/user;blah, which is of course wrong.
> Now, the server obviously doesn't know that it's sitting behind a proxy, so it needs to be told to generate the extra element in the URL path.  But how?
> The server is started up with:
>          (serve/servlet audiotag-dispatch
>                         #:servlet-path "podcasting/"
>                         #:servlet-regexp #rx""
>                         #:listen-ip #f ;listen on all interfaces (only loopback by default)
>                         #:port (port-number)
>                         #:launch-browser? #f
> #:servlet-path looks likely, here, but it doesn't seem to have the desired effect.  None of the other configuration parameters look likely either, and the contents of collects/web-server is too clever for my frazzled brain.  Can anyone advise?
> I apologise if the answer is RTFM, but I'm on a bit of a deadline, enough that it seems prudent to give in and ask quickly, rather than save my pride.
> Thanks for any pointers.
> Best wishes,
> Norman
> --
> Norman Gray  :  http://nxg.me.uk
> Dept Physics and Astronomy, University of Glasgow, UK
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users

Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University

"The glory of God is Intelligence" - D&C 93

Posted on the users mailing list.