Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve /drip semantics #132

Merged
merged 2 commits into from
Jun 29, 2023
Merged

Improve /drip semantics #132

merged 2 commits into from
Jun 29, 2023

Conversation

mccutchen
Copy link
Owner

This started with me wading into the /drip endpoint to add Server-Timing trailers as suggested in #72.

In making those changes, I discovered that the standard golang net/http server we're building on only supports sending trailers when the response is written using Content-Encoding: chunked. Initially, I thought it would be reasonable for this endpoint, which is designed to stream writes to the client, to switch over to a chunked response, but upon further consideration I don't think that's a good idea. So I'll defer adding trailers to some later work.

But, in thinking this through (and fighting with the unit tests already in place for drip), I realized that the /drip endpoint had room for improvement, if we think about it as an endpoint designed to let clients test their behavior when an HTTP server is responding very slowly.

So, we ended up with these changes:

  • Initial delay semantics
    • Originally, /drip would immediately write the desired status code and then wait for the initial delay (if any).
    • Here we update that so that it waits for the initial delay before writing anything to the response, to better simulate a server that is just very slow to respond at all.
  • Incremental write timings
    • Switch over to a ticker to more accurately pace the incremental writes across the requested duration
    • Stop sleeping after the final byte is written (should not affect clients, but avoids wasting server resources)

Worth noting that I now believe it's important that this endpoint not switch over to chunked content encoding, because it is useful to maintain and endpoint that simulates a server very slowly writing a "normal" HTTP response.

I'll consider adding trailers to an existing chunked endpoint, or potentially add a new, explicitly chunked endpoint to exercise that functionality.

httpbin/handlers.go Fixed Show fixed Hide fixed
@codecov
Copy link

codecov bot commented Jun 29, 2023

Codecov Report

Merging #132 (5605344) into main (0de8ec9) will increase coverage by 0.01%.
The diff coverage is 100.00%.

❗ Current head 5605344 differs from pull request most recent head 4ae08c0. Consider uploading reports for the commit 4ae08c0 to get more accurate results

@@            Coverage Diff             @@
##             main     #132      +/-   ##
==========================================
+ Coverage   98.06%   98.07%   +0.01%     
==========================================
  Files           8        8              
  Lines        1495     1506      +11     
==========================================
+ Hits         1466     1477      +11     
  Misses         21       21              
  Partials        8        8              
Impacted Files Coverage Δ
httpbin/handlers.go 99.45% <100.00%> (+<0.01%) ⬆️

@mccutchen mccutchen merged commit a670942 into main Jun 29, 2023
@mccutchen mccutchen deleted the drip-improvements branch June 29, 2023 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant