lib/assets/javascripts/unpoly/classes/request.coffee in unpoly-rails-0.51.1 vs lib/assets/javascripts/unpoly/classes/request.coffee in unpoly-rails-0.52.0
- old
+ new
@@ -95,28 +95,39 @@
normalize: =>
@method = u.normalizeMethod(@method)
@headers ||= {}
@extractHashFromUrl()
- if @data && !u.methodAllowsPayload(@method) && !u.isFormData(@data)
+
+ if u.methodAllowsPayload(@method)
+ @transferSearchToData()
+ else
@transferDataToUrl()
extractHashFromUrl: =>
urlParts = u.parseUrl(@url)
# Remember the #hash for later revealing.
# It will be lost during normalization.
@hash = urlParts.hash
@url = u.normalizeUrl(urlParts, hash: false)
transferDataToUrl: =>
- # GET methods are not allowed to have a payload, so we transfer { data } params to the URL.
- query = u.requestDataAsQuery(@data)
- separator = if u.contains(@url, '?') then '&' else '?'
- @url += separator + query
- # Now that we have transfered the params into the URL, we delete them from the { data } option.
- @data = undefined
+ if @data && !u.isFormData(@data)
+ # GET methods are not allowed to have a payload, so we transfer { data } params to the URL.
+ query = u.requestDataAsQuery(@data)
+ separator = if u.contains(@url, '?') then '&' else '?'
+ @url += separator + query
+ # Now that we have transfered the params into the URL, we delete them from the { data } option.
+ @data = undefined
+ transferSearchToData: =>
+ urlParts = u.parseUrl(@url)
+ query = urlParts.search
+ if query
+ @data = u.mergeRequestData(@data, query)
+ @url = u.normalizeUrl(urlParts, search: false)
+
isSafe: =>
up.proxy.isSafeMethod(@method)
send: =>
# We will modify this request below.
@@ -185,9 +196,11 @@
$form.attr(method: formMethod, action: @url)
if (csrfParam = up.protocol.csrfParam()) && (csrfToken = @csrfToken())
addField(name: csrfParam, value: csrfToken)
+ # @data will be undefined for GET requests, since we have already
+ # transfered all params to the URL during normalize().
u.each u.requestDataAsArray(@data), addField
$form.hide().appendTo('body')
up.browser.submitForm($form)