DoSomething / gladiator

:guardsman: The DoSomething.org competitions platform.
2 stars 0 forks source link

add content-length header to api routes #424

Closed sbsmith86 closed 7 years ago

sbsmith86 commented 7 years ago

What's this PR do?

Adds the content-length header to api responses.

How should this be manually tested?

Make an api request and see the content-length header in the set of response headers.

Any background context you want to provide?

Certain api requests were returning invalid JSON.

For example, https://gladiator.dosomething.org/api/v2/contests?page=22 , returns invalid JSON.

I used https://jsonlint.com/ to validate the response object and it is invalid, returning this error:

Error: Parse error on line 154:
...d469c644e398bfa97", "588e90d2a0bfad499f5
-----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'

It looks like it is trying to return the over 2000 users in one of the competitions under the contest and it cuts off the response, making the response invalid JSON. Digging into why this might happen and it looks like if we set the content-length header on the response it will specify how long the body of the response should be.

Open to other suggestions!

What are the relevant tickets?

Fixes https://www.pivotaltracker.com/story/show/150406511

sbsmith86 commented 7 years ago

@DFurnes I was thinking about reaching out to @blisteringherb about any server settings we could change. I can't figure out how to make the response shorter because quasar wants to ingest everything we have in gladiator and there are competitions with a lot of users in them. Short of just providing total counts, I'm not sure what we can do there.

sbsmith86 commented 7 years ago

@DFurnes updated to get the length of the actual HTTP response

DFurnes commented 7 years ago

@sbsmith86 Oh hmm, I think I might have actually lied on the Str::length usage - the Content-Length header should be giving the length in bytes, not "actual" characters, so str_len is probably the right usage here. Sorry! 😬