DEV Community


Discussion on: Crystal 1.0

jgaskins profile image
Jamie Gaskins

In that case, frameworks like Amber or Lucky are probably overkill. I would probably stick with using HTTP::Server directly:

require "http"

class Proxy
  include HTTP::Handler

  def call(context : HTTP::Server::Context)
    # Do proxy things here

http =[, # Log requests, # Gzip/Deflate response bodies,
http.listen "", 8080
Enter fullscreen mode Exit fullscreen mode

All of your PROXY protocol things would happen inside of (or downstream from) the Proxy#call method. The context passed to that method contains references to the request and response objects. You'd be able to stream things from the destination back to the requestor to keep your TTFB and memory footprint low, whereas I believe Amber builds the entire response in memory before sending it over the network.