erigon-pulse/cl/beacon/rw.go
a 47a6ac16da
[beacon handler] framework (#8851)
adds a two indexes to the validators cache

creates beaconhttp package with many utilities for beacon http endpoint
(future support for ssz is baked in)

started on some validator endpoints
2023-12-05 00:13:52 +01:00

43 lines
739 B
Go

package beacon
import (
"net/http"
)
type notFoundNoWriter struct {
rw http.ResponseWriter
code int
headers http.Header
}
func (f *notFoundNoWriter) Header() http.Header {
if f.code == 404 {
return make(http.Header)
}
return f.rw.Header()
}
func (f *notFoundNoWriter) Write(xs []byte) (int, error) {
// write code 200 if code not written yet
if f.code == 0 {
f.WriteHeader(200)
}
if f.code == 404 {
return 0, nil
}
// pass on the write
return f.rw.Write(xs)
}
func (f *notFoundNoWriter) WriteHeader(statusCode int) {
if f.code != 0 {
return
}
if f.code != 404 {
f.rw.WriteHeader(statusCode)
}
// if it's a 404 and we are not at our last handler, set the target to an io.Discard
f.code = statusCode
}