Skip to content

Commit 5e9cc05

Browse files
committed
closes #168
1 parent f6f046e commit 5e9cc05

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

ruby/hyper-operation/lib/hyper-operation/server_op.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff 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

ruby/hyper-operation/spec/hyper-operation/server_op_spec.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff 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
351375
end

0 commit comments

Comments
 (0)