Skip to content

Commit a207a8a

Browse files
authored
Merge pull request #50 from gtt-project/next
Adds service and ServicePath header to proxy request
2 parents df6d18d + 50f3707 commit a207a8a

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

app/controllers/subscription_templates_controller.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,19 @@ def handle_fiware_action(action)
237237
http = Net::HTTP.new(uri.host, uri.port)
238238
http.use_ssl = (uri.scheme == 'https')
239239

240+
headers = {
241+
'Authorization' => "Bearer #{@fiware_broker_auth_token}"
242+
}
243+
244+
headers['Content-Type'] = 'application/json' if action == 'publish'
245+
headers['Fiware-Service'] = @subscription_template.fiware_service if @subscription_template.fiware_service.present?
246+
headers['Fiware-ServicePath'] = @subscription_template.fiware_servicepath if @subscription_template.fiware_servicepath.present?
247+
240248
request = case action
241249
when 'publish'
242-
Net::HTTP::Post.new(uri.path, initheader = {
243-
'Content-Type' => 'application/json',
244-
'Authorization' => "Bearer #{@fiware_broker_auth_token}"
245-
}).tap { |req| req.body = @json_payload }
250+
Net::HTTP::Post.new(uri.path, headers).tap { |req| req.body = @json_payload }
246251
when 'unpublish'
247-
Net::HTTP::Delete.new(uri.path, initheader = {
248-
'Authorization' => "Bearer #{@fiware_broker_auth_token}"
249-
})
252+
Net::HTTP::Delete.new(uri.path, headers)
250253
else
251254
Rails.logger.error "Unknown action: #{action}"
252255
@error_message = l(:general_action_error)

0 commit comments

Comments
 (0)