From ba6a7c9dc81c690cccdcd4cbb2f0367c1e2a61b1 Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Wed, 5 Jan 2022 11:17:10 +0800 Subject: [PATCH] chore: refactor rest/timeouthandler (#1415) --- rest/handler/timeouthandler.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rest/handler/timeouthandler.go b/rest/handler/timeouthandler.go index cf0c7dd2..672f44b6 100644 --- a/rest/handler/timeouthandler.go +++ b/rest/handler/timeouthandler.go @@ -118,6 +118,9 @@ type timeoutWriter struct { var _ http.Pusher = (*timeoutWriter)(nil) +// Header returns the underline temporary http.Header. +func (tw *timeoutWriter) Header() http.Header { return tw.h } + // Push implements the Pusher interface. func (tw *timeoutWriter) Push(target string, opts *http.PushOptions) error { if pusher, ok := tw.w.(http.Pusher); ok { @@ -126,8 +129,8 @@ func (tw *timeoutWriter) Push(target string, opts *http.PushOptions) error { return http.ErrNotSupported } -func (tw *timeoutWriter) Header() http.Header { return tw.h } - +// Write writes the data to the connection as part of an HTTP reply. +// Timeout and multiple header written are guarded. func (tw *timeoutWriter) Write(p []byte) (int, error) { tw.mu.Lock() defer tw.mu.Unlock()