Socket
Book a DemoInstallSign in
Socket

rack-current

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rack-current

1.1.0
bundlerRubygems
Version published
Maintainers
1
Created
Source

Rack::Current

Sometimes, in the coures of human events, you need to access the currently executing http request, and you don't always have the luxury of passing it around, especially when you're working with frameworks that manage the lifecycle of objects for you, or you want to include functionality from a module. That module might not have a clean way of getting a reference to the request object.

Rack::Current can help

CurrentRequest stores the current request in a thread local so that you can access it from anywhere inside the request stack.

Oooh. Thread locals, those are dangerous I hear.

Not really. There are certain objects whose natural scope is the lifetime of an http request. The http request object itself is one such object. As long as the thread is the fundamental unit of concurrency in your server, you'll be ok.

That said, you should ensure that you are in fact including this into methods that will be invoked inside the request stack, and not, say, like a background job (like sending email) that is fired off during the course of a request.

Example

    class Foo
      include Rack::Curent

      def current_url
        "#{current_request.protocol}://#{current_request.host}/#{current_request.path}
      end
    end

FAQs

Package last updated on 05 Jul 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.