func (this *RequestMatcher) SaveRequestResponsePair(pair *models.RequestResponsePair) error { var key string if *this.Webserver { key = pair.IdWithoutHost() } else { key = pair.Id() } log.WithFields(log.Fields{ "path": pair.Request.Path, "rawQuery": pair.Request.Query, "requestMethod": pair.Request.Method, "bodyLen": len(pair.Request.Body), "destination": pair.Request.Destination, "hashKey": key, }).Debug("Capturing") pairBytes, err := pair.Encode() if err != nil { return err } return this.RequestCache.Set([]byte(key), pairBytes) }
func Test_rebuildHashes_whenDataIsHashedForAProxy_andStillAProxy_keysAreNotChanged(t *testing.T) { RegisterTestingT(t) webserver := false db := cache.NewInMemoryCache() pair := models.RequestResponsePair{ Request: models.RequestDetails{ Path: "/hello", Destination: "a-host.com", }, Response: models.ResponseDetails{ Body: "a body", }, } pairBytes, _ := pair.Encode() db.Set([]byte(pair.Id()), pairBytes) rebuildHashes(db, webserver) result, err := db.Get([]byte(pair.Id())) Expect(err).To(BeNil()) Expect(result).To(Equal(pairBytes)) }