emptygif
भाषा: हिन्दी

सभी भाषाएँ और फ़्रेमवर्क

Hanami Ruby

Hanami के लिए Ruby स्निपेट, जो /pixel.gif पर आने वाली रिक्वेस्ट का जवाब empty GIF से देता है। GIF स्टार्टअप पर एक ही बार डिकोड होता है।

Hanami Ruby

इंस्टॉल
gem install hanami && hanami new my_app
फ़ाइल
show.rb
चलाएँ
bundle exec hanami server --port 8080
# app/actions/pixel/show.rb
module MyApp
  module Actions
    module Pixel
      class Show < MyApp::Action
        GIF = "R0lGODlhAQABAIAAAP///wAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==".unpack1("m0").freeze

        def handle(request, response)
          # Rack's content_type= sets the exact header; format= would append "; charset=utf-8".
          response.content_type = "image/gif"
          response.headers["Cache-Control"] = "no-store"
          response.body = GIF
        end
      end
    end
  end
end

# config/routes.rb
module MyApp
  class Routes < Hanami::Routes
    get "/pixel.gif", to: "pixel.show"
  end
end

हमने यह स्निपेट चलाया और इसके लौटाए बाइट्स की तुलना की।

जाँचें

curl -sI http://localhost:8080/pixel.gif

आधिकारिक साइट: Hanami

Ruby में और