Esempio n. 1
0
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)
}
Esempio n. 2
0
func Test_rebuildHashes_whenDataIsHashedForAProxy_andIsNowAWebserver_keysAreChanged(t *testing.T) {
	RegisterTestingT(t)
	webserver := true

	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.IdWithoutHost()))

	Expect(err).To(BeNil())
	Expect(result).To(Equal(pairBytes))
}