rack on davidchua https://dchua.com/tags/rack/ Recent content in rack on davidchua Hugo -- gohugo.io en-us Tue, 12 Aug 2014 00:00:00 +0000 Testing with Rack-test custom headers https://dchua.com/posts/2014-08-12-testing-with-rack-test-custom-headers/ Tue, 12 Aug 2014 00:00:00 +0000 https://dchua.com/posts/2014-08-12-testing-with-rack-test-custom-headers/ When writing a method that requires a custom request header, ie. “X-Api-Key”, use the following: key = request.headers['HTTP_X_API_KEY'] Instead of key = request.headers['X-Api-Key'] This is because Rack converts all custom headers into the HTTP_ format. When writing your tests, remember to specify like the following get '/test', {}, {"HTTP_X_API_KEY" => "key"} Even though when in your actual query, you’re sending the header as X-Api-Key Creating my first Rack Middleware with Rack::ContentLength https://dchua.com/posts/2014-06-19-creating-my-first-rack-middleware/ Thu, 19 Jun 2014 00:00:00 +0000 https://dchua.com/posts/2014-06-19-creating-my-first-rack-middleware/ Yeah, I’m probably pretty slow in the game but I think I’ve finally wrapped my head around all the countless Rack Middlewares out there. The goal of this was to create a response_logger that intercepts the response object on the middleware level and send out a log with the size of the JSON object that it returns for future reference. I first setup Rack::ContentLength, which is a great Middleware that’s available out of the box if you’re on Rails.