Skip to content

Instantly share code, notes, and snippets.

@julik
Created February 11, 2021 19:21
Show Gist options
  • Save julik/e14c37fe9e811bb899317796136397aa to your computer and use it in GitHub Desktop.
Save julik/e14c37fe9e811bb899317796136397aa to your computer and use it in GitHub Desktop.
PAYLOAD_SIZE = 15 * 1024 * 1024
CHUNK_SIZE = 65 * 1024 # Roughly one socket buffer
class StufferBody
def each
rng = Random.new(123)
whole_chunks, rem = PAYLOAD_SIZE.divmod(CHUNK_SIZE)
whole_chunks.times do
yield(rng.bytes(CHUNK_SIZE))
end
yield(rng.bytes(rem)) if rem > 0
end
end
stuffer = ->(_env) {
[200, {'Content-Length' => PAYLOAD_SIZE.to_s}, StufferBody.new]
}
run stuffer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment