MCPcopy Index your code
hub / github.com/zalando/skipper / ExampleForwardBackend

Function ExampleForwardBackend

eskip/example_test.go:231–273  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

229}
230
231func ExampleForwardBackend() {
232 backend := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
233 w.WriteHeader(http.StatusOK)
234 }))
235 defer backend.Close()
236
237 doc := `r: * -> <forward>;`
238 routes := eskip.MustParse(doc)
239
240 spec := builtin.NewStatus()
241 fr := make(filters.Registry)
242 fr.Register(spec)
243
244 dc := testdataclient.New(routes)
245 defer dc.Close()
246
247 proxy := proxytest.WithRoutingOptions(fr, routing.Options{
248 DataClients: []routing.DataClient{dc},
249 PreProcessors: []routing.PreProcessor{eskip.ForwardPreProcessor(backend.URL)},
250 })
251 defer proxy.Close()
252
253 client := proxy.Client()
254 req, err := http.NewRequest("GET", proxy.URL, nil)
255 if err != nil {
256 fmt.Printf("Failed to create request: %v\n", err)
257 }
258
259 rsp, err := client.Do(req)
260 if err != nil {
261 fmt.Printf("Failed to GET hello.example: %v\n", err)
262 return
263 }
264 defer rsp.Body.Close()
265 if rsp.StatusCode != http.StatusOK {
266 fmt.Printf("Failed to GET OK from http://hello.example, got: %v\n", rsp.StatusCode)
267 return
268 }
269 fmt.Println("hello skipper")
270
271 // output:
272 // hello skipper
273}

Callers

nothing calls this directly

Calls 10

MustParseFunction · 0.92
NewStatusFunction · 0.92
NewFunction · 0.92
WithRoutingOptionsFunction · 0.92
ForwardPreProcessorFunction · 0.92
RegisterMethod · 0.80
ClientMethod · 0.80
CloseMethod · 0.65
DoMethod · 0.65
WriteHeaderMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…