DEV Community

Discussion on: Crystal 1.0

Collapse
 
rayandfz profile image
Rayan Desfossez

Yes

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

http = HTTP::Server.new([
  HTTP::LogHandler.new, # Log requests
  HTTP::CompressHandler.new, # Gzip/Deflate response bodies
  Proxy.new,
])
http.listen "0.0.0.0", 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.