2017-04-24 22:13:19 +03:00
|
|
|
// Copyright 2017 The Prometheus Authors
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
// +build go1.8
|
|
|
|
|
|
|
|
package promhttp
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
2017-06-02 19:55:31 +03:00
|
|
|
type pusherDelegator struct{ *responseWriterDelegator }
|
|
|
|
|
2018-07-13 00:56:21 +03:00
|
|
|
func (d pusherDelegator) Push(target string, opts *http.PushOptions) error {
|
2017-06-02 19:55:31 +03:00
|
|
|
return d.ResponseWriter.(http.Pusher).Push(target, opts)
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
pickDelegator[pusher] = func(d *responseWriterDelegator) delegator { // 16
|
2018-07-13 00:56:21 +03:00
|
|
|
return pusherDelegator{d}
|
2017-06-02 19:55:31 +03:00
|
|
|
}
|
|
|
|
pickDelegator[pusher+closeNotifier] = func(d *responseWriterDelegator) delegator { // 17
|
|
|
|
return struct {
|
|
|
|
*responseWriterDelegator
|
|
|
|
http.Pusher
|
|
|
|
http.CloseNotifier
|
2018-07-13 00:56:21 +03:00
|
|
|
}{d, pusherDelegator{d}, closeNotifierDelegator{d}}
|
2017-06-02 19:55:31 +03:00
|
|
|
}
|
|
|
|
pickDelegator[pusher+flusher] = func(d *responseWriterDelegator) delegator { // 18
|
|
|
|
return struct {
|
|
|
|
*responseWriterDelegator
|
|
|
|
http.Pusher
|
|
|
|
http.Flusher
|
2018-07-13 00:56:21 +03:00
|
|
|
}{d, pusherDelegator{d}, flusherDelegator{d}}
|
2017-06-02 19:55:31 +03:00
|
|
|
}
|
|
|
|
pickDelegator[pusher+flusher+closeNotifier] = func(d *responseWriterDelegator) delegator { // 19
|
|
|
|
return struct {
|
|
|
|
*responseWriterDelegator
|
|
|
|
http.Pusher
|
|
|
|
http.Flusher
|
|
|
|
http.CloseNotifier
|
2018-07-13 00:56:21 +03:00
|
|
|
}{d, pusherDelegator{d}, flusherDelegator{d}, closeNotifierDelegator{d}}
|
2017-06-02 19:55:31 +03:00
|
|
|
}
|
|
|
|
pickDelegator[pusher+hijacker] = func(d *responseWriterDelegator) delegator { // 20
|
|
|
|
return struct {
|
|
|
|
*responseWriterDelegator
|
|
|
|
http.Pusher
|
|
|
|
http.Hijacker
|
2018-07-13 00:56:21 +03:00
|
|
|
}{d, pusherDelegator{d}, &hijackerDelegator{d}}
|
2017-06-02 19:55:31 +03:00
|
|
|
}
|
|
|
|
pickDelegator[pusher+hijacker+closeNotifier] = func(d *responseWriterDelegator) delegator { // 21
|
|
|
|
return struct {
|
|
|
|
*responseWriterDelegator
|
|
|
|
http.Pusher
|
|
|
|
http.Hijacker
|
|
|
|
http.CloseNotifier
|
2018-07-13 00:56:21 +03:00
|
|
|
}{d, pusherDelegator{d}, &hijackerDelegator{d}, closeNotifierDelegator{d}}
|
2017-06-02 19:55:31 +03:00
|
|
|
}
|
|
|
|
pickDelegator[pusher+hijacker+flusher] = func(d *responseWriterDelegator) delegator { // 22
|
|
|
|
return struct {
|
|
|
|
*responseWriterDelegator
|
|
|
|
http.Pusher
|
|
|
|
http.Hijacker
|
|
|
|
http.Flusher
|
2018-07-13 00:56:21 +03:00
|
|
|
}{d, pusherDelegator{d}, &hijackerDelegator{d}, flusherDelegator{d}}
|
2017-06-02 19:55:31 +03:00
|
|
|
}
|
|
|
|
pickDelegator[pusher+hijacker+flusher+closeNotifier] = func(d *responseWriterDelegator) delegator { //23
|
|
|
|
return struct {
|
|
|
|
*responseWriterDelegator
|
|
|
|
http.Pusher
|
|
|
|
http.Hijacker
|
|
|
|
http.Flusher
|
|
|
|
http.CloseNotifier
|
2018-07-13 00:56:21 +03:00
|
|
|
}{d, pusherDelegator{d}, &hijackerDelegator{d}, flusherDelegator{d}, closeNotifierDelegator{d}}
|
2017-06-02 19:55:31 +03:00
|
|
|
}
|
|
|
|
pickDelegator[pusher+readerFrom] = func(d *responseWriterDelegator) delegator { // 24
|
|
|
|
return struct {
|
|
|
|
*responseWriterDelegator
|
|
|
|
http.Pusher
|
|
|
|
io.ReaderFrom
|
2018-07-13 00:56:21 +03:00
|
|
|
}{d, pusherDelegator{d}, readerFromDelegator{d}}
|
2017-06-02 19:55:31 +03:00
|
|
|
}
|
|
|
|
pickDelegator[pusher+readerFrom+closeNotifier] = func(d *responseWriterDelegator) delegator { // 25
|
|
|
|
return struct {
|
|
|
|
*responseWriterDelegator
|
|
|
|
http.Pusher
|
|
|
|
io.ReaderFrom
|
|
|
|
http.CloseNotifier
|
2018-07-13 00:56:21 +03:00
|
|
|
}{d, pusherDelegator{d}, readerFromDelegator{d}, closeNotifierDelegator{d}}
|
2017-06-02 19:55:31 +03:00
|
|
|
}
|
|
|
|
pickDelegator[pusher+readerFrom+flusher] = func(d *responseWriterDelegator) delegator { // 26
|
|
|
|
return struct {
|
|
|
|
*responseWriterDelegator
|
|
|
|
http.Pusher
|
|
|
|
io.ReaderFrom
|
|
|
|
http.Flusher
|
2018-07-13 00:56:21 +03:00
|
|
|
}{d, pusherDelegator{d}, readerFromDelegator{d}, flusherDelegator{d}}
|
2017-06-02 19:55:31 +03:00
|
|
|
}
|
|
|
|
pickDelegator[pusher+readerFrom+flusher+closeNotifier] = func(d *responseWriterDelegator) delegator { // 27
|
|
|
|
return struct {
|
|
|
|
*responseWriterDelegator
|
|
|
|
http.Pusher
|
|
|
|
io.ReaderFrom
|
|
|
|
http.Flusher
|
|
|
|
http.CloseNotifier
|
2018-07-13 00:56:21 +03:00
|
|
|
}{d, pusherDelegator{d}, readerFromDelegator{d}, flusherDelegator{d}, closeNotifierDelegator{d}}
|
2017-06-02 19:55:31 +03:00
|
|
|
}
|
|
|
|
pickDelegator[pusher+readerFrom+hijacker] = func(d *responseWriterDelegator) delegator { // 28
|
|
|
|
return struct {
|
|
|
|
*responseWriterDelegator
|
|
|
|
http.Pusher
|
|
|
|
io.ReaderFrom
|
|
|
|
http.Hijacker
|
2018-07-13 00:56:21 +03:00
|
|
|
}{d, pusherDelegator{d}, readerFromDelegator{d}, &hijackerDelegator{d}}
|
2017-06-02 19:55:31 +03:00
|
|
|
}
|
|
|
|
pickDelegator[pusher+readerFrom+hijacker+closeNotifier] = func(d *responseWriterDelegator) delegator { // 29
|
|
|
|
return struct {
|
|
|
|
*responseWriterDelegator
|
|
|
|
http.Pusher
|
|
|
|
io.ReaderFrom
|
|
|
|
http.Hijacker
|
|
|
|
http.CloseNotifier
|
2018-07-13 00:56:21 +03:00
|
|
|
}{d, pusherDelegator{d}, readerFromDelegator{d}, &hijackerDelegator{d}, closeNotifierDelegator{d}}
|
2017-06-02 19:55:31 +03:00
|
|
|
}
|
|
|
|
pickDelegator[pusher+readerFrom+hijacker+flusher] = func(d *responseWriterDelegator) delegator { // 30
|
|
|
|
return struct {
|
|
|
|
*responseWriterDelegator
|
|
|
|
http.Pusher
|
|
|
|
io.ReaderFrom
|
|
|
|
http.Hijacker
|
|
|
|
http.Flusher
|
2018-07-13 00:56:21 +03:00
|
|
|
}{d, pusherDelegator{d}, readerFromDelegator{d}, &hijackerDelegator{d}, flusherDelegator{d}}
|
2017-06-02 19:55:31 +03:00
|
|
|
}
|
|
|
|
pickDelegator[pusher+readerFrom+hijacker+flusher+closeNotifier] = func(d *responseWriterDelegator) delegator { // 31
|
|
|
|
return struct {
|
|
|
|
*responseWriterDelegator
|
|
|
|
http.Pusher
|
|
|
|
io.ReaderFrom
|
|
|
|
http.Hijacker
|
|
|
|
http.Flusher
|
|
|
|
http.CloseNotifier
|
2018-07-13 00:56:21 +03:00
|
|
|
}{d, pusherDelegator{d}, readerFromDelegator{d}, &hijackerDelegator{d}, flusherDelegator{d}, closeNotifierDelegator{d}}
|
2017-06-02 19:55:31 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-29 12:42:43 +03:00
|
|
|
func newDelegator(w http.ResponseWriter, observeWriteHeaderFunc func(int)) delegator {
|
|
|
|
d := &responseWriterDelegator{
|
|
|
|
ResponseWriter: w,
|
|
|
|
observeWriteHeader: observeWriteHeaderFunc,
|
|
|
|
}
|
2017-04-24 22:13:19 +03:00
|
|
|
|
2017-06-02 19:55:31 +03:00
|
|
|
id := 0
|
|
|
|
if _, ok := w.(http.CloseNotifier); ok {
|
|
|
|
id += closeNotifier
|
|
|
|
}
|
|
|
|
if _, ok := w.(http.Flusher); ok {
|
|
|
|
id += flusher
|
|
|
|
}
|
|
|
|
if _, ok := w.(http.Hijacker); ok {
|
|
|
|
id += hijacker
|
|
|
|
}
|
|
|
|
if _, ok := w.(io.ReaderFrom); ok {
|
|
|
|
id += readerFrom
|
|
|
|
}
|
|
|
|
if _, ok := w.(http.Pusher); ok {
|
|
|
|
id += pusher
|
2017-04-24 22:13:19 +03:00
|
|
|
}
|
|
|
|
|
2017-06-02 19:55:31 +03:00
|
|
|
return pickDelegator[id](d)
|
2017-04-24 22:13:19 +03:00
|
|
|
}
|