Hi all,
I'd need to write a very simple reverse proxy and I'm wondering what's
the best way to do it in racket. I don't have any requirements but
performance (not even security and reliability, since I'm writing
basically a testing tool).

I came out with this solution (using http-sendrecv/url). It  seems
working properly for everything but redirects:

(define (handle-file-request req)
    (define uri (request-uri req))
    (define method (request-method req))
    (define post-data (request-post-data/raw req))
    (define proxy-headers
        (map
        (lambda (h) (bytes-append (header-field h) #": " (header-value h)))
        (filter (lambda (h) (not (bytes=? (header-field h) #"Host"))) headers)))

    (let-values
        ([(status headers in)
            (http-sendrecv/url
              (struct-copy url uri [scheme remote-scheme)] [host
remote-host] [port remote-port])
              #:method method
              #:headers proxy-headers
              #:data post-data)])

        (let ([mime (findf identity (map (lambda (h) (extract-field
#"content-type" h)) headers))])
          (response
            200 #"OK"
            (current-seconds) (if mime mime #"text/javascript; charset=UTF-8")
            empty
            (λ (client-out) (write-bytes (port->bytes in) client-out)))))


Do you think is this one the right way or do you think there is a
better (cleaner/more performing) approach? Any idea about how to
manage redirects if not manually?

Thanks,
Andrea

-- 
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