Skip to content

Instantly share code, notes, and snippets.

@dbreunig
Last active December 1, 2024 20:18
Show Gist options
  • Save dbreunig/2a571e31c2d31e188aee91b3ec3c18d7 to your computer and use it in GitHub Desktop.
Save dbreunig/2a571e31c2d31e188aee91b3ec3c18d7 to your computer and use it in GitHub Desktop.
How to respond to a DuckDB request – identified by the fairly rare user agent 'cpp-httplib' – in a Rails controller, returning a database file in the `public` folder.
class HomeController < ApplicationController
def index
# Intercept DuckDB requests
if request.user_agent =~ /cpp-httplib/
send_file(Rails.root.join('public', 'public_lists.db'),
type: 'application/octet-stream',
disposition: 'attachment')
return
end
# Handle non-DuckDB requests...
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment