MCPcopy
hub / github.com/harness/harness / Value

Method Value

registry/app/dist_temp/dcontext/http.go:137–171  ·  view source on GitHub ↗

Value returns a keyed element of the request for use in the context. To get the request itself, query "request". For other components, access them as "request. ". For example, r.RequestURI.

(key interface{})

Source from the content-addressed store, hash-verified

135// the request itself, query "request". For other components, access them as
136// "request.<component>". For example, r.RequestURI.
137func (ctx *httpRequestContext) Value(key interface{}) interface{} {
138 if keyStr, ok := key.(string); ok {
139 switch keyStr {
140 case "http.request":
141 return ctx.r
142 case "http.request.uri":
143 return ctx.r.RequestURI
144 case "http.request.remoteaddr":
145 return requestutil.RemoteAddr(ctx.r)
146 case "http.request.method":
147 return ctx.r.Method
148 case "http.request.host":
149 return ctx.r.Host
150 case "http.request.referer":
151 referer := ctx.r.Referer()
152 if referer != "" {
153 return referer
154 }
155 case "http.request.useragent":
156 return ctx.r.UserAgent()
157 case "http.request.id":
158 return ctx.id
159 case "http.request.startedat":
160 return ctx.startedAt
161 case "http.request.contenttype":
162 if ct := ctx.r.Header.Get("Content-Type"); ct != "" {
163 return ct
164 }
165 default:
166 // no match; fall back to standard behavior below
167 }
168 }
169
170 return ctx.Context.Value(key)
171}
172
173type muxVarsContext struct {
174 context.Context

Callers

nothing calls this directly

Calls 3

RemoteAddrFunction · 0.92
GetMethod · 0.65
ValueMethod · 0.45

Tested by

no test coverage detected