Skip to content

Commit

Permalink
Merge pull request #50 from gtt-project/next
Browse files Browse the repository at this point in the history
Adds service and ServicePath header to proxy request
  • Loading branch information
dkastl authored Jul 4, 2024
2 parents df6d18d + 50f3707 commit a207a8a
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 a207a8a

Please sign in to comment.