File: internal_response_writer.go

package info (click to toggle)
golang-github-newrelic-go-agent 3.15.2-9
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 8,356 kB
  • sloc: sh: 65; makefile: 6
file content (157 lines) | stat: -rw-r--r-- 3,232 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// Copyright 2020 New Relic Corporation. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package newrelic

import (
	"bufio"
	"io"
	"net"
	"net/http"

	"github.com/newrelic/go-agent/internal"
)

func (thd *thread) CloseNotify() <-chan bool {
	return thd.txn.getWriter().(http.CloseNotifier).CloseNotify()
}
func (thd *thread) Flush() {
	thd.txn.getWriter().(http.Flusher).Flush()
}
func (thd *thread) Hijack() (net.Conn, *bufio.ReadWriter, error) {
	return thd.txn.getWriter().(http.Hijacker).Hijack()
}
func (thd *thread) ReadFrom(r io.Reader) (int64, error) {
	return thd.txn.getWriter().(io.ReaderFrom).ReadFrom(r)
}

type threadWithExtras interface {
	Transaction
	internal.AddAgentAttributer
	internal.AddAgentSpanAttributer
}

func upgradeTxn(thd *thread) Transaction {
	// Note that thd.txn.getWriter() is not used here.  The transaction is
	// locked (or under construction) when this function is used.

	// GENERATED CODE DO NOT MODIFY
	// This code generated by internal/tools/interface-wrapping
	var (
		i0 int32 = 1 << 0
		i1 int32 = 1 << 1
		i2 int32 = 1 << 2
		i3 int32 = 1 << 3
	)
	var interfaceSet int32
	if _, ok := thd.txn.writer.(http.CloseNotifier); ok {
		interfaceSet |= i0
	}
	if _, ok := thd.txn.writer.(http.Flusher); ok {
		interfaceSet |= i1
	}
	if _, ok := thd.txn.writer.(http.Hijacker); ok {
		interfaceSet |= i2
	}
	if _, ok := thd.txn.writer.(io.ReaderFrom); ok {
		interfaceSet |= i3
	}
	switch interfaceSet {
	default: // No optional interfaces implemented
		return struct {
			threadWithExtras
		}{thd}
	case i0:
		return struct {
			threadWithExtras
			http.CloseNotifier
		}{thd, thd}
	case i1:
		return struct {
			threadWithExtras
			http.Flusher
		}{thd, thd}
	case i0 | i1:
		return struct {
			threadWithExtras
			http.CloseNotifier
			http.Flusher
		}{thd, thd, thd}
	case i2:
		return struct {
			threadWithExtras
			http.Hijacker
		}{thd, thd}
	case i0 | i2:
		return struct {
			threadWithExtras
			http.CloseNotifier
			http.Hijacker
		}{thd, thd, thd}
	case i1 | i2:
		return struct {
			threadWithExtras
			http.Flusher
			http.Hijacker
		}{thd, thd, thd}
	case i0 | i1 | i2:
		return struct {
			threadWithExtras
			http.CloseNotifier
			http.Flusher
			http.Hijacker
		}{thd, thd, thd, thd}
	case i3:
		return struct {
			threadWithExtras
			io.ReaderFrom
		}{thd, thd}
	case i0 | i3:
		return struct {
			threadWithExtras
			http.CloseNotifier
			io.ReaderFrom
		}{thd, thd, thd}
	case i1 | i3:
		return struct {
			threadWithExtras
			http.Flusher
			io.ReaderFrom
		}{thd, thd, thd}
	case i0 | i1 | i3:
		return struct {
			threadWithExtras
			http.CloseNotifier
			http.Flusher
			io.ReaderFrom
		}{thd, thd, thd, thd}
	case i2 | i3:
		return struct {
			threadWithExtras
			http.Hijacker
			io.ReaderFrom
		}{thd, thd, thd}
	case i0 | i2 | i3:
		return struct {
			threadWithExtras
			http.CloseNotifier
			http.Hijacker
			io.ReaderFrom
		}{thd, thd, thd, thd}
	case i1 | i2 | i3:
		return struct {
			threadWithExtras
			http.Flusher
			http.Hijacker
			io.ReaderFrom
		}{thd, thd, thd, thd}
	case i0 | i1 | i2 | i3:
		return struct {
			threadWithExtras
			http.CloseNotifier
			http.Flusher
			http.Hijacker
			io.ReaderFrom
		}{thd, thd, thd, thd, thd}
	}
}