#REST headers XML
1 messages · Page 1 of 1 (latest)
Would it make sense to only map the known headers strict and just look at leftover content?
so XML header -> parse XML, JSON header -> parse JSON, different header -> check if it's XML or JSON
I think it would be better to allow configuring the data type
oh that's also a good one
should we suggest that?
I already left a review as prek was failing
But it went stale, let's first check if they get back
Why wait? If we have some other idea, we should suggest that now to not waste time?
Oh yea sure, I wasn't behind my desk then
Ah, I misunderstood. I thought you wanted to wait until after the auther was active in the PR again,
I think that's also a bit what I meant
To be honest, I would not even add a option to select the data type as the device is sending the data completely wrong
Sure, but then the options are
- Try to parse it
- Users can't use the rest integration because their device is not doing something correct
- Have the user explicitly set the type
- Have a list of exceptions or headers to take into account
The problem with having an option would mean we are ignoring the content type and try to parse is as specified and that could lead to bugs. Also if you have a device, which sends sometime XML and sometime json would not work anymore. I don't have a concrete example and I don't even expect that some device will do it but currently it would be possible, which will be prevented if a config option
Sure, if an endpoint provides data in a specific case, that wouldn't be covered. However
- That's and edge case
- You'd at least assume that it would change headers if that's a feature
But if that happens today, then the REST integration wouldn't work for that device either
Currently the rest integration just works fine if the content type changes between requests
but I didn't want to break that
Sorry but the PR is really an edge case, where a device is sending a wrong content type header, which is not matching the returned data
We could make an optional key to force a certain type, because we can't parse everything
Yes, but we receive data fine, the only limiting factor is us not being able to map it
Wait maybe I have an idea
We could add an accept header to the rest integration https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Accept so we tell the device which data we can understand
The HTTP Accept request and response header indicates which content types, expressed as MIME types, the sender is able to understand.
In requests, the server uses content negotiation to select one of the proposals and informs the client of the choice with the Content-Type response header.
In responses, it provides information about which content...
Also can you ask the user to try to manually add it? Some devices are checking it and returning then the correct data format. Maybe this will help
I guess we can try, but I think that's a separate discussion
Like if they already don't care about the headers we're getting back, I can see a world where this doesn't work
It's worth a try as it would fix the issue for him without any changes. You can already set headers
and we should set them as we just accept certain types
At this point I am convinced it will probably break a lot of very niche devices 😅