File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed
Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ def run(*args)
1414 Hyperstack ::HTTP . post (
1515 "#{ `window.HyperstackEnginePath` } /execute_remote" ,
1616 payload : { json : { operation : name , params : hash } . to_json } ,
17- headers : { 'X-CSRF-Token' => Hyperstack ::ClientDrivers . opts [ :form_authenticity_token ] }
17+ headers : headers . merge ( 'X-CSRF-Token' => Hyperstack ::ClientDrivers . opts [ :form_authenticity_token ] )
1818 )
1919 . then do |response |
2020 deserialize_response response . json [ :response ]
@@ -129,6 +129,10 @@ def remote(path, *args)
129129 promise . reject e
130130 end
131131
132+ def headers
133+ { }
134+ end
135+
132136 def serialize_params ( hash )
133137 hash
134138 end
Original file line number Diff line number Diff line change @@ -347,5 +347,29 @@ def self.deserialize_dispatch(hash)
347347 end . to eq ( 6 )
348348 expect ( page ) . to have_content ( "The server says 'hello serialized deserialized'!" )
349349 end
350+
351+ it 'can attach custom headers' do
352+ isomorphic do
353+ class Operation < Hyperstack ::ControllerOp
354+
355+ def self . headers # this runs on the client and adds custom headers
356+ { Authorization : '1234' }
357+ end
358+
359+ # return the value of the Authorization header
360+ # rails automatically upcases all the keys
361+
362+ step { request . headers [ 'AUTHORIZATION' ] }
363+ end
364+ end
365+ stub_const "OperationPolicy" , Class . new
366+ OperationPolicy . always_allow_connection
367+ mount 'Test'
368+
369+ expect_promise do
370+ Operation . run
371+ end . to eq ( '1234' )
372+ end
373+
350374 end
351375end
You can’t perform that action at this time.
0 commit comments