> PS if you're running the Racket web server as a proxy behind Apache, then 
> `request-client-ip` will always be the localhost IP. However, Apache stores 
> the original request IP in special header called X-Forwarded-For [1] which 
> can be retrieved like so:

Same header with nginx or AWS ELB in front.


If you're having Apache/nginx/ELB/whatever handle SSL, and the Racket
web server itself is plain http, then you may also be interested in
X-Forwarded-Proto.


For example, if you want to redirect http to https -- a nice thing to
do for users -- you could do something like:

(define/contract ((wrap-http->https handler) req) wrapper?
  (match (headers-assq* #"x-forwarded-proto" (request-headers/raw req))
    [(header _ #"http")
     (redirect-to (path->external-uri
                   (url->string (struct-copy url (request-uri req)
                                             [scheme #f]
                                             [port   #f])))
                  permanently)]
    [_ (handler req)]))

p.s. This is using a "wrapper" style of composing handlers, where:

(define handler? (-> request? response?))
(define wrapper? (-> handler? handler?))

and the basic `dispatch` handler might be wrapped with something like this:

(serve/servlet (~> ;Note: requests go UP this chain, responses DOWN
                  dispatch
                  wrap-gzip
                  wrap-not-modified
                  wrap-authorize
                  wrap-authenticate
                  wrap-http->https
                  wrap-timed-and-logged)
                 #:servlet-path      "/"
                 #:servlet-regexp    #px""
                 #:listen-ip         #f
                 #:port              (current-internal-port) ;e.g. 8080
                 #:launch-browser?   (not (current-production))
                 #:servlet-responder error-responder)

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to