Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Host Header missing in notification #1343

Closed
sjerman opened this issue Mar 23, 2023 · 5 comments
Closed

Host Header missing in notification #1343

sjerman opened this issue Mar 23, 2023 · 5 comments

Comments

@sjerman
Copy link

sjerman commented Mar 23, 2023

Hi. I just spent a while trying to figure out why tomcat was returning 400 silently for each notification sent. Looks like the Host header is needed.

This is the subscription:

{
   "id":"urn:ngsi-ld:subscription:1af7864c-c949-11ed-8416-0242ac140003",
   "status":"active",
   "origin":"cache",
   "watchedAttributes":[
      "value"
   ],
   "description":"Notify me of change sets",
   "type":"Subscription",
   "entities":[
      {
         "type":"BinarySensor"
      }
   ],
   "notification":{
      "attributes":[
         "value",
         "pointId"
      ],
      "format":"keyValues",
      "endpoint":{
         "uri":"http://192.168.1.108:8080/test/events",
         "accept":"application/json"
      },
      "status":"failed",
      "timesSent":2,
      "lastNotification":"2023-03-23T07:15:50.680Z",
      "lastFailure":"2023-03-23T07:15:50.680Z",
      "consecutiveErrors":2,
      "lastErrorReason":"non 2xx response to notification"
   },
   "isActive":true
}

This is the payload sent:

POST /test/events?subscriptionId=urn:ngsi-ld:subscription:1af7864c-c949-11ed-8416-0242ac140003 HTTP/1.1
Content-Length: 314
Content-Type: application/json
User-Agent: orionld/post-v1.1.0
Accept: application/json
Ngsild-Attribute-Format: Simplified
Link: <https://registry.kloudspot.com/repository/files/fiware/datamodels.context-ngsi.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"

{"id":"urn:ngsi-ld:Notification:1c9f2ce8-c949-11ed-ad65-0242ac140003","type":"Notification","subscriptionId":"urn:ngsi-ld:subscription:1af7864c-c949-11ed-8416-0242ac140003","notifiedAt":"2023-03-23T07:05:36.832Z","data":[{"id":"urn:ngsi-ld:BinarySensor:001","type":"BinarySensor","pointId":"docker","value":true}]}

A 400 error is returned by tomcat before it gets to the application level...

Note no header...

I can simulate this with CURL..

curl -v http://192.168.1.108:8080/test/events?subscriptionId=urn:ngsi-ld:subscription:1af7864c-c949-11ed-8416-0242ac140003 \
   -H 'Content-Type: application/json' \
   -H 'Accept: application/json' \
   -H 'Ngsild-Attribute-Format: Simplified' \
   -H 'Link: <https://registry.kloudspot.com/repository/files/fiware/datamodels.context-ngsi.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
   -d '{"id":"urn:ngsi-ld:Notification:1c9f2ce8-c949-11ed-ad65-0242ac140003","type":"Notification","subscriptionId":"urn:ngsi-ld:subscription:1af7864c-c949-11ed-8416-0242ac140003","notifiedAt":"2023-03-23T07:05:36.832Z","data":[{"id":"urn:ngsi-ld:BinarySensor:001","type":"BinarySensor","pointId":"docker","value":true}]}'

works

curl -v http://192.168.1.108:8080/test/events?subscriptionId=urn:ngsi-ld:subscription:1af7864c-c949-11ed-8416-0242ac140003 \
   -H 'Content-Type: application/json' \
   -H 'Accept: application/json' \
   -H 'Host:' \
   -H 'Ngsild-Attribute-Format: Simplified' \
   -H 'Link: <https://registry.kloudspot.com/repository/files/fiware/datamodels.context-ngsi.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
   -d '{"id":"urn:ngsi-ld:Notification:1c9f2ce8-c949-11ed-ad65-0242ac140003","type":"Notification","subscriptionId":"urn:ngsi-ld:subscription:1af7864c-c949-11ed-8416-0242ac140003","notifiedAt":"2023-03-23T07:05:36.832Z","data":[{"id":"urn:ngsi-ld:BinarySensor:001","type":"BinarySensor","pointId":"docker","value":true}]}'

doesn't

Just FYI... I think it is now a required header:
https://www.rfc-editor.org/rfc/rfc9110.html#name-host-and-authority

@kzangeli
Copy link
Collaborator

ok, easy fix. I'll just add the host header then :)

@kzangeli
Copy link
Collaborator

Thanks for reporting!!!

@sjerman
Copy link
Author

sjerman commented Mar 23, 2023 via email

kzangeli added a commit that referenced this issue Mar 23, 2023
kzangeli added a commit that referenced this issue Mar 23, 2023
@kzangeli
Copy link
Collaborator

Should be working now.
I take as hostname what "gethostname" gives back.
I could let the users decide by adding a CLI for it, jsut not sure that's a very good idea ...

Test it and if all is good, please go ahead and close this issue.
And if not, just describe what's not good and I'll try to fix it.

@sjerman
Copy link
Author

sjerman commented Mar 31, 2023

Sorry for the delay. This is fixed. Thanks.

@sjerman sjerman closed this as completed Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants