closeAll closes all ongoing sessions, for tests. TODO(rfindley): investigate the best API for callers to configure their session lifecycle. (?) Should we allow passing in a session store? That would allow the handler to be stateless.
()
| 217 | // Should we allow passing in a session store? That would allow the handler to |
| 218 | // be stateless. |
| 219 | func (h *StreamableHTTPHandler) closeAll() { |
| 220 | // TODO: if we ever expose this outside of tests, we'll need to do better |
| 221 | // than simply collecting sessions while holding the lock: we need to prevent |
| 222 | // new sessions from being added. |
| 223 | // |
| 224 | // Currently, sessions remove themselves from h.sessions when closed, so we |
| 225 | // can't call Close while holding the lock. |
| 226 | h.mu.Lock() |
| 227 | sessionInfos := slices.Collect(maps.Values(h.sessions)) |
| 228 | h.sessions = nil |
| 229 | h.mu.Unlock() |
| 230 | for _, s := range sessionInfos { |
| 231 | s.session.Close() |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | // disablelocalhostprotection is a compatibility parameter that allows to disable |
| 236 | // DNS rebinding protection, which was added in the 1.4.0 version of the SDK. |