From 69edb6e5ea43ed698e524255ccff61b7696f7424 Mon Sep 17 00:00:00 2001 From: Kanezoh Date: Mon, 9 Aug 2021 08:34:46 +0900 Subject: [PATCH] add post_form to cur_page --- src/mechanize.cr | 4 ++-- src/mechanize/form.cr | 1 + src/mechanize/http/agent.cr | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/mechanize.cr b/src/mechanize.cr index bebf532..7130938 100644 --- a/src/mechanize.cr +++ b/src/mechanize.cr @@ -38,9 +38,9 @@ class Mechanize post_form(uri, form, headers) end + # send POST request from form. def post_form(uri, form, headers) - #cur_page = form.page || current_page || - # Page.new + cur_page = form.page || (current_page unless history.empty?) request_data = form.request_data content_headers = ::HTTP::Headers{ diff --git a/src/mechanize/form.cr b/src/mechanize/form.cr index 21a766c..21f235a 100644 --- a/src/mechanize/form.cr +++ b/src/mechanize/form.cr @@ -20,6 +20,7 @@ class MechanizeCr::Form getter enctype : String getter method : String getter name : String + getter page : Page? property action : String def initialize(node : Node | Myhtml::Node, page : Page? = nil) diff --git a/src/mechanize/http/agent.cr b/src/mechanize/http/agent.cr index 10dc306..da8a3a4 100644 --- a/src/mechanize/http/agent.cr +++ b/src/mechanize/http/agent.cr @@ -18,7 +18,9 @@ module MechanizeCr @user_agent = "" end - def fetch(uri, method = :get, headers = HTTP::Headers.new, params = Hash(String,String).new) + def fetch(uri, method = :get, headers = HTTP::Headers.new, params = Hash(String,String).new, + )#referer = current_page) + #referer_uri = referer.uri uri = resolve(uri) set_request_headers(uri, headers) set_user_agent