geoadmin / service-alti

Height/profile services for geo.admin.ch
Other
2 stars 2 forks source link

BGDIINF_SB-2375: Fixed callback parameter responses #101

Closed ltshb closed 2 years ago

ltshb commented 2 years ago

The callback query parameter has two minor issues and was also not very efficient when used on the profile.json endpoint.

The first issue was that if given to the profile.csv endpoint it would have transformed the CSV output by wrapping it with the value of callback and marked the output as javascript. However this was an invalid javascript output as CSV is not a javascript valid syntax. This bug has been introduced with the dockerization, before in this case the callback query was simply ignored. Now it is not ignored but returns a 400 HTTP status.

The second minor issue, which was more a syntax sugar, was that using the callback query, a useless LF character was added at the end of the json data.

The last issue was about efficiency especially used on a big data output (200 points). Although I did not measure the time penalty (so it might have been negligible), I change it to be more efficient and it make also IMHO the code cleaner. The issue was that the data in the response object is binary and due to the implicit call of Flask make_response for a JSON output the \n LF character was added. So using the after_response flask hook did introduced an unwanted \n see above but also the profile.json behavior see above as well, in this hook we had to decode and parse the binary output again and then to encode it again. So now without using this hook we change the output to javascript before encoding it with make_response. This is slightly more efficient and require lest IO and CPU.