StackStorm / st2web

StackStorm Web UI
http://www.stackstorm.com/features
Apache License 2.0
102 stars 83 forks source link

Handle cases where `content-type` is not exactly `application/json` #982

Closed luislobo closed 2 years ago

luislobo commented 2 years ago

Fixes https://github.com/StackStorm/st2web/issues/981

Our production Nginx configuration has set charset utf-8; making Content-Type header to be application/json; charset=utf-8, not just application/json. @stackstorm/module-api compares headers['content-type'] to be exactly application/json.

Some comments about the request function:

Some possible improvements/questions:

  1. Should raw return the data without doing any JSON.parse? If so, then transformResponse should not be used.
  2. On line 234, body is assigned data. Assuming data is a string at this moment, body is not a pointer of data, but rather a copy. Then, the changes done on body on lines 244-248 (for parsing JSON) are superfluous, since the function is returning data.
  3. Line 232 could be done before 229, and not have to repeat defaulting to {} on both 229 and 230.

Let us know about those comments/questions and we can apply changes as needed.

luislobo commented 2 years ago

@amanda11 @armab

I'd appreciate if you can check this one out when you have a chance.

Thank you

amanda11 commented 2 years ago

think I've found the problem with st2web, and I'm looking at a PR to fix.

amanda11 commented 2 years ago

@luislobo If you can merge in latest master this should hopefully build ok now.

luislobo commented 2 years ago

Sure, will do.

luislobo commented 2 years ago

Seems like tests passed now :)