Ejemplo n.º 1
0
// Uses gorilla/context. Returns the legs for the request. Automatically parses
// the legs if they have not been parsed yet and caches the outcome using
// gorilla/context. If you aren't yourself using gorilla/context, remember to
// set it up to clear context data for exiting requests.
func Legs(req *http.Request) []originfuncs.Leg {
	v, ok := context.GetOk(req, &legsKey)
	if !ok {
		v = originfuncs.Parse(req)
		context.Set(req, &legsKey, v)
	}
	return v.([]originfuncs.Leg)
}
Ejemplo n.º 2
0
func TestOrigin(t *testing.T) {
	for i := range tests {
		legs := originfuncs.Parse(tests[i].req)
		if !reflect.DeepEqual(legs, tests[i].legs) {
			t.Fatalf("leg mismatch: %v != %v", legs, tests[i].legs)
		}
	}
}