Skip to content

Commit

Permalink
Merge pull request #35 from tarent/feature/TOOM-3692-Add-correlation-…
Browse files Browse the repository at this point in the history
…id-in-http-header

Feature/toom 3692 add correlation id in http header
  • Loading branch information
stweiz committed Dec 8, 2016
2 parents 5ddf18b + 6433d23 commit 4849120
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
cover.out
cover.out
/.idea
2 changes: 1 addition & 1 deletion composition/composition_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func Test_CompositionHandler_CorrectHeaderAndStatusCodeReturned(t *testing.T) {
ch.ServeHTTP(resp, r)

a.Equal(200, resp.Code)
a.Equal(3, len(resp.Header())) // Set-Cookie + Content-Type + Content-Lenth
a.Equal(3, len(resp.Header())) // Set-Cookie + Content-Type + Content-Length
a.Equal("", resp.Header().Get("Transfer-Encoding"))
a.Contains(resp.Header()["Set-Cookie"], "cookie-content 1")
a.Contains(resp.Header()["Set-Cookie"], "cookie-content 2")
Expand Down
9 changes: 4 additions & 5 deletions composition/content_fetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,13 @@ func (fetcher *ContentFetcher) WaitForResults() []*FetchResult {
return results
}

// AddFetchJob addes one job to the fetcher and recursively adds the dependencies also.
// AddFetchJob adds one job to the fetcher and recursively adds the dependencies also.
func (fetcher *ContentFetcher) AddFetchJob(d *FetchDefinition) {
fetcher.r.mutex.Lock()
defer fetcher.r.mutex.Unlock()

hash := d.Hash()
if fetcher.isAlreadySheduled(hash) {
if fetcher.isAlreadyScheduled(hash) {
return
}

Expand Down Expand Up @@ -128,7 +128,6 @@ func (fetcher *ContentFetcher) AddFetchJob(d *FetchDefinition) {
WithField("correlation_id", logging.GetCorrelationId(definitionCopy.Header)).
Errorf("failed fetching %v", d.URL)
}

}
}()
}
Expand All @@ -139,9 +138,9 @@ func (fetcher *ContentFetcher) Empty() bool {
return len(fetcher.r.results) == 0
}

// isAlreadySheduled checks, if there is already a job for a FetchDefinition, or it is already fetched.
// isAlreadyScheduled checks, if there is already a job for a FetchDefinition, or it is already fetched.
// The method has to be called in a locked mutex block.
func (fetcher *ContentFetcher) isAlreadySheduled(fetchDefinitionHash string) bool {
func (fetcher *ContentFetcher) isAlreadyScheduled(fetchDefinitionHash string) bool {
for _, fetchResult := range fetcher.r.results {
if fetchDefinitionHash == fetchResult.Hash {
return true
Expand Down
5 changes: 3 additions & 2 deletions composition/fetch_definition.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
const MAX_PRIORITY int = 4294967295

// ForwardRequestHeaders are those headers,
// which are incuded from the original client request to the backend request.
// which are included from the original client request to the backend request.
// TODO: Add Host header to an XFF header
var ForwardRequestHeaders = []string{
"Authorization",
Expand All @@ -34,7 +34,7 @@ var ForwardRequestHeaders = []string{
}

// ForwardResponseHeaders are those headers,
// which are incuded from the servers backend response to the client.
// which are included from the servers backend response to the client.
var ForwardResponseHeaders = []string{
"Age",
"Allow",
Expand Down Expand Up @@ -207,6 +207,7 @@ func copyHeaders(src, dest http.Header, whitelist []string) http.Header {
dest.Add(k, v)
}
}

return dest
}

Expand Down
2 changes: 2 additions & 0 deletions composition/fetch_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func Test_FetchDefinition_NewFetchDefinitionFromRequest(t *testing.T) {
"Cookie": {"aa=bb;"},
"X-Feature-Toggle": {"true"},
"Accept-Encoding": {"gzip"}, // should not be copied
"X-Correlation-Id": {"foobar123"},
}

fd := NewFetchDefinitionFromRequest("http://upstream:8080/", r)
Expand All @@ -32,6 +33,7 @@ func Test_FetchDefinition_NewFetchDefinitionFromRequest(t *testing.T) {
a.Equal("aa=bb;", fd.Header.Get("Cookie"))
a.Equal("true", fd.Header.Get("X-Feature-Toggle"))
a.Equal("", fd.Header.Get("Accept-Encoding"))
a.Equal("foobar123", fd.Header.Get("X-Correlation-Id"))

a.Equal("POST", fd.Method)
b, err := ioutil.ReadAll(fd.Body)
Expand Down

0 comments on commit 4849120

Please sign in to comment.