emptygif
ਭਾਸ਼ਾ: ਪੰਜਾਬੀ

ਸਾਰੀਆਂ ਭਾਸ਼ਾਵਾਂ ਅਤੇ ਫਰੇਮਵਰਕ

Hanami Ruby

Hanami ਲਈ Ruby ਸਨਿੱਪਟ, ਜੋ /pixel.gif ਦੀਆਂ ਬੇਨਤੀਆਂ ਦਾ ਜਵਾਬ ਖਾਲੀ 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 ਵਿੱਚ ਹੋਰ