Skip to content

Commit

Permalink
Make default headers config driven
Browse files Browse the repository at this point in the history
  • Loading branch information
tejaswiagarwal committed Oct 31, 2019
1 parent fe0b53c commit f0051d8
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 10 deletions.
5 changes: 4 additions & 1 deletion codegen/template_bundle/template_files.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions codegen/templates/http_client.tmpl
Expand Up @@ -78,6 +78,9 @@ func {{$exportName}}(deps *module.Dependencies) Client {
timeoutVal,
)
defaultHeaders := make(map[string]string)
if deps.Default.Config.ContainsKey("http.defaultHeaders") {
deps.Default.Config.MustGetStruct("http.defaultHeaders", &defaultHeaders)
}
if deps.Default.Config.ContainsKey("clients.{{$clientID}}.defaultHeaders") {
deps.Default.Config.MustGetStruct("clients.{{$clientID}}.defaultHeaders", &defaultHeaders)
}
Expand Down
3 changes: 3 additions & 0 deletions examples/example-gateway/build/clients/bar/bar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/example-gateway/build/clients/contacts/contacts.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/example-gateway/build/clients/multi/multi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions examples/example-gateway/config/production.yaml
Expand Up @@ -66,6 +66,9 @@ tchannel.port: 7784
tchannel.processName: example-gateway
tchannel.serviceName: example-gateway
tchannel.clients.requestUUIDHeaderKey: x-request-uuid
http.defaultHeaders:
Accept: application/json
Content-Type: application/json
useDatacenter: false
clients.baz.alternates:
routingConfigs:
Expand Down
3 changes: 3 additions & 0 deletions examples/example-gateway/config/test.yaml
Expand Up @@ -67,6 +67,9 @@ tchannel.port: 0
tchannel.processName: example-gateway
tchannel.serviceName: example-gateway
tchannel.clients.requestUUIDHeaderKey: x-request-uuid
http.defaultHeaders:
Accept: application/json
Content-Type: application/json
useDatacenter: false
clients.baz.alternates:
routingConfigs:
Expand Down
9 changes: 0 additions & 9 deletions runtime/client_http_request.go
Expand Up @@ -171,15 +171,6 @@ func (req *ClientHTTPRequest) WriteJSON(
httpReq.Header.Set(k, headers[k])
}

if body != nil {
httpReq.Header.Set(http.CanonicalHeaderKey(contentTypeHeader), contentTypeHeaderValue)
}

/* Only unmarshal JSON is supported today so set this as default if none present */
if _, ok := headers[http.CanonicalHeaderKey(acceptHeader)]; !ok {
httpReq.Header.Set(acceptHeader, acceptHeaderValue)
}

req.httpReq = httpReq
req.ctx = WithLogFields(req.ctx,
zap.String(logFieldClientHTTPMethod, method),
Expand Down

0 comments on commit f0051d8

Please sign in to comment.