diff --git a/src/mechanize.cr b/src/mechanize.cr index 4f87bec..1c94a99 100644 --- a/src/mechanize.cr +++ b/src/mechanize.cr @@ -101,4 +101,14 @@ class Mechanize def add_to_history(page) history.push(page) end + + # Get maximum number of items allowed in the history. The default setting is 100 pages. + def max_history + history.max_size + end + + # Set maximum number of items allowed in the history. + def max_history=(length) + history.max_size = length + end end diff --git a/src/mechanize/history.cr b/src/mechanize/history.cr index f002b2a..b20272e 100644 --- a/src/mechanize/history.cr +++ b/src/mechanize/history.cr @@ -1,7 +1,7 @@ require "./page" class MechanizeCr::History < Array(MechanizeCr::Page) - property :max_size + property max_size : Int32 def initialize(max_size = 100) @max_size = max_size super diff --git a/src/mechanize/http/agent.cr b/src/mechanize/http/agent.cr index ec232a1..1bb7874 100644 --- a/src/mechanize/http/agent.cr +++ b/src/mechanize/http/agent.cr @@ -53,6 +53,16 @@ module MechanizeCr @history.pop end + # Get maximum number of items allowed in the history. The default setting is 100 pages. + def max_history + @history.max_size + end + + # Set maximum number of items allowed in the history. + def max_history=(length) + @history.max_size = length + end + private def set_request_headers(uri, headers) reset_request_header_cookies headers.each do |k,v|