The Crystal Programming Language Forum

Possible to check whether I can call IO::Buffered#buffer_size=?

According to the documentation for IO::Buffered#buffer_size=(value):

Cannot be changed after any of the buffers have been allocated

It raises an exception, but I don’t see a way to tell me whether the buffer has been allocated so I can’t tell if I can set it without raising an exception. It seems that there isn’t a method for it.

The reason I’m asking is because I render my app’s page header to the response before routing, and if that 8KB buffer fills up, it flushes and I can no longer change headers or status code (primarily used for redirect calls during routing). To avoid that early flush, I’m setting the output buffer for my HTTP responses a little higher, but apparently instances of HTTP::Server::Response (and their associated output) are reused between requests to reduce garbage. This means I can only set the output buffer size on the response the first time it appears.

Is there already a solution for this that I’m overlooking or should I send a PR?