<commit_before># -*- coding: utf-8 -*-
# = セッションIDの付与
require 'active_support/version'

module ParamsOverCookie
  def self.included(base)
    base.class_eval do
      # cookie よりも params を先に見るパッチ
      def load_session_with_jpmobile(env)
        request = Rack::Request.new(env)
        unless @cookie_only
          sid = request.params[@key]
        end
        sid ||= request.cookies[@key]

        sid, session = get_session(env, sid)
        [sid, session]
      end
      alias_method_chain :load_session, :jpmobile
    end
  end
end

module ActionController
  # cookie よりも params を先に見るパッチ
  Session::AbstractStore.send :include, ParamsOverCookie

  class Base #:nodoc:
    class_inheritable_accessor :trans_sid_mode
    alias :redirect_to_full_url_without_jpmobile :redirect_to_full_url

    def transit_sid_mode(*args)
      STDERR.puts "Method transit_sid is now deprecated. Use trans_sid instead."
      trans_sid_mode(*args)
    end

    def redirect_to_full_url(url, status)
      if apply_trans_sid? and !url.match(/#{session_key}/)
        uri = URI.parse(url)
        if uri.query
          uri.query += "&#{session_key}=#{jpmobile_session_id}"
        else
          uri.query = "#{session_key}=#{jpmobile_session_id}"
        end
        url = uri.to_s
      end

      redirect_to_full_url_without_jpmobile(url, status)
    end

    class << self
      # 2.3.x or higher
      def trans_sid(mode = :mobile)
        include Jpmobile::TransSid
        self.trans_sid_mode = mode
      end

      def transit_sid(*args)
        STDERR.puts "Method transit_sid is now deprecated. Use trans_sid instead."
        trans_sid(*args)
      end
    end

    private
    # trans_sidを適用すべきかを返す。
    def apply_trans_sid?
      return false if (jpmobile_session_id rescue nil).blank?
      return false if trans_sid_mode == :none
      return true if trans_sid_mode == :always
      if trans_sid_mode == :mobile
        if request.mobile?
          return !request.mobile.supports_cookie?
        else
          return false
        end
      end
      return false
    end
  end<commit_msg>autoload session when trans_sid is enabled. gh-1<commit_after># -*- coding: utf-8 -*-
# = セッションIDの付与
require 'active_support/version'

module ParamsOverCookie
  def self.included(base)
    base.class_eval do
      # cookie よりも params を先に見るパッチ
      def load_session_with_jpmobile(env)
        request = Rack::Request.new(env)
        unless @cookie_only
          sid = request.params[@key]
        end
        sid ||= request.cookies[@key]

        sid, session = get_session(env, sid)
        [sid, session]
      end
      alias_method_chain :load_session, :jpmobile
    end
  end
end

module ActionController
  # cookie よりも params を先に見るパッチ
  Session::AbstractStore.send :include, ParamsOverCookie

  class Base #:nodoc:
    class_inheritable_accessor :trans_sid_mode
    alias :redirect_to_full_url_without_jpmobile :redirect_to_full_url

    def transit_sid_mode(*args)
      STDERR.puts "Method transit_sid is now deprecated. Use trans_sid instead."
      trans_sid_mode(*args)
    end

    def redirect_to_full_url(url, status)
      if apply_trans_sid? and !url.match(/#{session_key}/)
        uri = URI.parse(url)
        if uri.query
          uri.query += "&#{session_key}=#{jpmobile_session_id}"
        else
          uri.query = "#{session_key}=#{jpmobile_session_id}"
        end
        url = uri.to_s
      end

      redirect_to_full_url_without_jpmobile(url, status)
    end

    class << self
      # 2.3.x or higher
      def trans_sid(mode = :mobile)
        include Jpmobile::TransSid
        self.trans_sid_mode = mode
      end

      def transit_sid(*args)
        STDERR.puts "Method transit_sid is now deprecated. Use trans_sid instead."
        trans_sid(*args)
      end
    end

    private
    # trans_sidを適用すべきかを返す。
    def apply_trans_sid?
      return false if (jpmobile_session_id rescue nil).blank?

      case trans_sid_mode
      when :always
        session.inspect
        return true
      when :mobile
        if request.mobile? and !request.mobile.supports_cookie?
          session.inspect
          return true
        end
      end

      return false
    end
  end
{'fraction_non_alphanumeric': 0.08008555133079848, 'fraction_numerical': 0.0016634980988593155, 'mean_word_length': 2.455665024630542, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '325553', 'n_tokens_mistral': 1401, 'n_tokens_neox': 1375, 'n_words': 313}