Skip to content

Commit

Permalink
Merge pull request #45 from 40ants/a-few-changes
Browse files Browse the repository at this point in the history
A few changes
  • Loading branch information
svetlyak40wt authored Oct 21, 2023
2 parents ee8b395 + 4ffbafa commit 8d8954e
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/actions.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ situation (e.g. redirect, signal an error, etc.)."))
(reblocks/request:get-parameters)))
(params (list* (cons *action-string*
action-code)
old-params)))
(remove *action-string*
old-params
:key #'car
:test #'string-equal))))
(concatenate 'string
(get-path) ;; Current URL path
"?"
Expand Down
18 changes: 18 additions & 0 deletions src/doc/changelog.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,24 @@
"REBLOCKS/SESSION:INIT")
:external-links (("Ultralisp" . "https://ultralisp.org"))
:external-docs ("https://40ants.com/log4cl-extras/"))
(0.54.0 2023-10-22
"""
Added
=====
Function REBLOCKS/REQUEST:GET-REMOTE-IP was added.
Fixed
=====
Now function REBLOCKS/ACTIONS:MAKE-ACTION-URL removed old `action` argument if it is present in the
current URL. This fixes the case when you want to make an action url from the callback processing
another action.
JavaScript function `initiateFormAction` now does not overwrites whole options.args object,
but only replaces the keys corresponding to a form data fields.
""")
(0.53.0 2023-06-20
"""
Changed
Expand Down
2 changes: 2 additions & 0 deletions src/doc/request.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"HTTP"
"AJAX"
"HTML"
"IP"
"JSON"
"URL"))
"""
Expand All @@ -38,6 +39,7 @@
(reblocks/request:remove-header function)
(reblocks/request:get-uri function)
(reblocks/request:get-path function)
(reblocks/request:get-remote-ip function)
(reblocks/request-handler:handle-request generic-function)
(reblocks/request-handler:handle-ajax-request generic-function)
(reblocks/request-handler:*request-timeout* variable)
Expand Down
2 changes: 1 addition & 1 deletion src/js/jquery/jquery.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ function initiateFormAction(actionCode, form, options) {
var action_arguments = form.serializeObjectWithSubmit();
delete(action_arguments['action']);

options['args'] = action_arguments;
options['args'] = Object.assign({}, options.args || {}, action_arguments);
options['method'] = options['method'] || form.attr('method');
initiateAction(actionCode, options);
}
Expand Down
12 changes: 11 additions & 1 deletion src/request.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
(:import-from #:quri)
(:import-from #:str
#:split)
(:import-from #:lack.request
#:request-remote-addr)

(:export #:get-parameters
#:get-parameter
Expand All @@ -42,7 +44,8 @@
#:get-path
#:with-request
#:pure-request-p
#:get-cookie))
#:get-cookie
#:get-remote-ip))
(in-package #:reblocks/request)


Expand Down Expand Up @@ -234,3 +237,10 @@ if there is an action involved (even if the user hits refresh)."
,result)))


(defun get-remote-ip (&key (request *request*))
"Returns a possible user's IP.
Note, it may not be reliable, because user might try to set these headers manually."
(or (get-header "x-real-ip" :request request)
(get-header "x-forwarded-for" :request request)
(request-remote-addr request)))

0 comments on commit 8d8954e

Please sign in to comment.