Skip to content

Commit

Permalink
Adds service and ServicePath header to proxy request
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kastl <[email protected]>
  • Loading branch information
dkastl committed Jun 20, 2024
1 parent 48851f0 commit 50f3707
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions app/controllers/subscription_templates_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,19 @@ def handle_fiware_action(action)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = (uri.scheme == 'https')

headers = {
'Authorization' => "Bearer #{@fiware_broker_auth_token}"
}

headers['Content-Type'] = 'application/json' if action == 'publish'
headers['Fiware-Service'] = @subscription_template.fiware_service if @subscription_template.fiware_service.present?
headers['Fiware-ServicePath'] = @subscription_template.fiware_servicepath if @subscription_template.fiware_servicepath.present?

request = case action
when 'publish'
Net::HTTP::Post.new(uri.path, initheader = {
'Content-Type' => 'application/json',
'Authorization' => "Bearer #{@fiware_broker_auth_token}"
}).tap { |req| req.body = @json_payload }
Net::HTTP::Post.new(uri.path, headers).tap { |req| req.body = @json_payload }
when 'unpublish'
Net::HTTP::Delete.new(uri.path, initheader = {
'Authorization' => "Bearer #{@fiware_broker_auth_token}"
})
Net::HTTP::Delete.new(uri.path, headers)
else
Rails.logger.error "Unknown action: #{action}"
@error_message = l(:general_action_error)
Expand Down

0 comments on commit 50f3707

Please sign in to comment.