socketry / falcon

A high-performance web server for Ruby, supporting HTTP/1, HTTP/2 and TLS.
https://socketry.github.io/falcon/
MIT License
2.54k stars 79 forks source link

Sure! Here's what we're trying to do. This is a bit simplified, but the issue with Rack vs. Rails responses still applies. #244

Open ioquatix opened 1 month ago

ioquatix commented 1 month ago
          Sure! Here's what we're trying to do. This is a bit simplified, but the issue with Rack vs. Rails responses still applies.
  def query
    rack_response = Rack::Response.new

    rack_response.body = lambda do |stream|
      rack_response.set_header('Last-Modified', Time.now.httpdate) # Prevent Rack ETag middleware from buffering the response
      rack_response.set_header('Content-Type', 'application/json')

      stream.write("#{Oj.dump({ scheduling: true }, mode: :compat)}\n")

      response = Typhoeus.get('https://example.com')
      rack_response.status = response.code
      stream.write(response_data)
    rescue StandardError => e
      stream.write({ error: "[#{token_hash}] Unknown error" }.to_json)
      rack_response.status = :internal_server_error
    end

    self.response = rack_response
  end

Originally posted by @gyfis in https://github.com/socketry/falcon/issues/164#issuecomment-2016476243