rust-lang/rust-by-example — pull request #346 by dbbrian (2014-12-21 21:33:13+00:00)
Title: Check the size of the response before appending it to the DOM. Close #177

The problem occurred when the response was [appended to the DOM](https://github.com/rust-lang/rust-by-example/blob/master/node_modules/gitbook-plugin-rust-playpen/book/editor.js#L200). The rest of the code can handle a pretty large volume of data, I tested it with responses up to ~150MB before Firefox threw an `allocation size overflow`. Thanks to that, we're able to check the length of the response, and truncate it if necessary, before touching the DOM, and avoid a crash.

I've set the `MAX_RESPONSE_LENGTH ` to 50,000 characters. Above that the response is truncated (25,000 from the head, 25,000 from the tail.)