Skip to content

Remove deprecated http.CloseNotifier and replace with Request.Context().Done() #4586

@haesuo566

Description

@haesuo566

Feature Description

Summary

The http.CloseNotifier interface has been officially deprecated since Go 1.11.
Gin's Stream method currently calls w.CloseNotify() directly, and the ResponseWriter
interface embeds http.CloseNotifier. This change replaces it with Request.Context().Done(),
which is the recommended approach in the Go standard library.


Motivation

The Go documentation states the following about http.CloseNotifier:

Deprecated: the CloseNotifier interface predates Go's context package.
New code should use Request.Context instead.

Continuing to use http.CloseNotifier may trigger deprecation warnings and risks breakage
if it is eventually removed from the standard library.
Additionally, Request.Context().Done() covers a broader set of termination scenarios,
including context timeout and cancellation, not just client disconnection.

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/proposalGot an idea for a feature that Gin doesn't have currently? Submit your idea here!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions