Commit ce27c1a
refactor: add SSE Builder::on_response hook (#537)
## Summary
Adds an `on_response` hook to `sse::Builder`, invoked once per
(re)connect after the HTTP response headers have been received, before
any branching on status. Fires for every response (any status, including
redirects and errors); does not fire if the connection failed before any
response (TCP error, read timeout).
Prep for upcoming FDv2 work that needs to inspect the `X-LD-FD-Fallback`
response header.
## Design notes
cURL backend accumulates header lines into a per-transfer
`http::response_header<>` on `RequestContext`, because `HeaderCallback`
is invoked once per CRLF-terminated line. The hook fires on the empty
terminator and is posted to the client strand.
## Test plan
- [x] `gtest_launchdarkly-sse-client` — green under both Foxy and cURL
backends
- [x] New `ClientTest.OnResponseHookFiresWithCustomHeader`
<!-- CURSOR_SUMMARY -->
---
> [!NOTE]
> **Medium Risk**
> Touches reconnect/header parsing on both Foxy and cURL SSE paths; cURL
header assembly is new logic though covered by existing and new client
tests.
>
> **Overview**
> Adds **`sse::Builder::on_response`**, a callback that runs **once per
connect/reconnect** right after response headers are parsed and
**before** status-based handling (success, redirect, errors). It
receives a `http::response_header<>` so callers can read headers such as
**`X-LD-FD-Fallback`** without waiting for the SSE body.
>
> **Foxy** backend invokes the hook synchronously on the client executor
when header parsing completes. **cURL** backend rebuilds the prior
Content-Type-only header sniffing into full **line-by-line header
assembly** (status line, OWS trimming, duplicate headers via `insert()`,
redirect chains), emits the hook on the blank line after headers, and
**posts** it to the same executor as other callbacks. Header accumulator
state is reset on each new transfer.
>
> Includes **`ClientTest.OnResponseHookFiresWithCustomHeader`** for
status and custom header visibility.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
733ec51. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
---------
Co-authored-by: Ryan Lamb <4955475+kinyoklion@users.noreply.github.com>1 parent f1e7555 commit ce27c1a
5 files changed
Lines changed: 226 additions & 11 deletions
File tree
- libs/server-sent-events
- include/launchdarkly/sse
- src
- tests
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
| |||
196 | 198 | | |
197 | 199 | | |
198 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
199 | 215 | | |
200 | 216 | | |
201 | 217 | | |
| |||
219 | 235 | | |
220 | 236 | | |
221 | 237 | | |
| 238 | + | |
222 | 239 | | |
223 | 240 | | |
224 | 241 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
| |||
87 | 88 | | |
88 | 89 | | |
89 | 90 | | |
| 91 | + | |
90 | 92 | | |
91 | 93 | | |
92 | 94 | | |
| |||
256 | 258 | | |
257 | 259 | | |
258 | 260 | | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
259 | 264 | | |
260 | 265 | | |
261 | 266 | | |
| |||
517 | 522 | | |
518 | 523 | | |
519 | 524 | | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
520 | 529 | | |
521 | 530 | | |
522 | 531 | | |
| |||
650 | 659 | | |
651 | 660 | | |
652 | 661 | | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
653 | 667 | | |
654 | 668 | | |
655 | 669 | | |
| |||
697 | 711 | | |
698 | 712 | | |
699 | 713 | | |
700 | | - | |
701 | | - | |
| 714 | + | |
| 715 | + | |
702 | 716 | | |
703 | 717 | | |
704 | 718 | | |
| |||
720 | 734 | | |
721 | 735 | | |
722 | 736 | | |
723 | | - | |
| 737 | + | |
| 738 | + | |
724 | 739 | | |
725 | 740 | | |
726 | 741 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| 10 | + | |
9 | 11 | | |
| 12 | + | |
10 | 13 | | |
11 | 14 | | |
12 | 15 | | |
| |||
41 | 44 | | |
42 | 45 | | |
43 | 46 | | |
| 47 | + | |
44 | 48 | | |
45 | 49 | | |
46 | 50 | | |
| |||
51 | 55 | | |
52 | 56 | | |
53 | 57 | | |
| 58 | + | |
54 | 59 | | |
55 | 60 | | |
56 | 61 | | |
| |||
149 | 154 | | |
150 | 155 | | |
151 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
152 | 170 | | |
153 | 171 | | |
154 | 172 | | |
| |||
397 | 415 | | |
398 | 416 | | |
399 | 417 | | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
400 | 423 | | |
401 | 424 | | |
402 | 425 | | |
403 | 426 | | |
404 | 427 | | |
405 | 428 | | |
406 | 429 | | |
407 | | - | |
408 | | - | |
409 | | - | |
410 | | - | |
411 | | - | |
412 | | - | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
413 | 510 | | |
414 | 511 | | |
415 | 512 | | |
| |||
426 | 523 | | |
427 | 524 | | |
428 | 525 | | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
429 | 531 | | |
430 | 532 | | |
431 | 533 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
52 | 53 | | |
53 | 54 | | |
54 | 55 | | |
55 | 56 | | |
56 | 57 | | |
57 | | - | |
| 58 | + | |
| 59 | + | |
58 | 60 | | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
62 | | - | |
| 64 | + | |
| 65 | + | |
63 | 66 | | |
64 | 67 | | |
65 | 68 | | |
| |||
94 | 97 | | |
95 | 98 | | |
96 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
97 | 110 | | |
98 | 111 | | |
99 | 112 | | |
| |||
158 | 171 | | |
159 | 172 | | |
160 | 173 | | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
161 | 184 | | |
162 | 185 | | |
163 | 186 | | |
| |||
238 | 261 | | |
239 | 262 | | |
240 | 263 | | |
| 264 | + | |
241 | 265 | | |
242 | 266 | | |
243 | 267 | | |
| |||
294 | 318 | | |
295 | 319 | | |
296 | 320 | | |
| 321 | + | |
297 | 322 | | |
298 | 323 | | |
299 | 324 | | |
| |||
0 commit comments