Created
February 11, 2021 19:21
-
-
Save julik/e14c37fe9e811bb899317796136397aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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