Skip to content

Commit

Permalink
Merge pull request #665 from uber/add_application/json
Browse files Browse the repository at this point in the history
Add application/json too all requests by default
  • Loading branch information
tejaswiagarwal committed Oct 31, 2019
2 parents 3270596 + a7407ab commit e670e4d
Show file tree
Hide file tree
Showing 13 changed files with 35 additions and 5 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 @@ -46,6 +46,9 @@ clients.withexceptions.timeout: 10000
clients.withexceptions.maxConcurrentRequests: 1000
clients.withexceptions.errorPercentThreshold: 20
envVarsToTagInRootScope: []
http.defaultHeaders:
Accept: application/json
Content-Type: application/json
http.port: 7783
http.clients.requestUUIDHeaderKey: x-request-uuid
logger.fileName: /var/log/example-gateway/example-gateway.log
Expand Down
3 changes: 3 additions & 0 deletions examples/example-gateway/config/test.yaml
Expand Up @@ -45,6 +45,9 @@ clients.withexceptions.maxConcurrentRequests: 1000
clients.withexceptions.errorPercentThreshold: 20
env: test
envVarsToTagInRootScope: []
http.defaultHeaders:
Accept: application/json
Content-Type: application/json
http.port: 0
http.clients.requestUUIDHeaderKey: x-request-uuid
logger.fileName: /tmp/example-gateway.log
Expand Down
4 changes: 0 additions & 4 deletions runtime/client_http_request.go
Expand Up @@ -164,10 +164,6 @@ func (req *ClientHTTPRequest) WriteJSON(
httpReq.Header.Set(k, headers[k])
}

if body != nil {
httpReq.Header.Set("Content-Type", "application/json")
}

req.httpReq = httpReq
req.ctx = WithLogFields(req.ctx,
zap.String(logFieldClientHTTPMethod, method),
Expand Down
3 changes: 3 additions & 0 deletions runtime/client_http_request_test.go
Expand Up @@ -145,6 +145,7 @@ func TestMakingClientCallWithHeaders(t *testing.T) {
_, _ = w.Write([]byte(r.Header.Get("Example-Header")))
// Check that the default header got set and actually sent to the server.
assert.Equal(t, r.Header.Get("X-Client-ID"), "bar")
assert.Equal(t, r.Header.Get("Accept"), "application/test+json")
},
)

Expand All @@ -160,6 +161,7 @@ func TestMakingClientCallWithHeaders(t *testing.T) {
client.BaseURL+"/bar-path",
map[string]string{
"Example-Header": "Example-Value",
"Accept": "application/test+json",
},
nil,
)
Expand Down Expand Up @@ -284,6 +286,7 @@ func TestMakingClientCallWithRespHeaders(t *testing.T) {
"clientHTTPMethod": "POST",
"Client-Req-Header-X-Client-Id": "bar",
"Client-Req-Header-Content-Type": "application/json",
"Client-Req-Header-Accept": "application/json",
"Client-Res-Header-Example-Header": "Example-Value",
"Client-Res-Header-Content-Type": "text/plain; charset=utf-8",
}
Expand Down
1 change: 1 addition & 0 deletions test/endpoints/bar/bar_metrics_test.go
Expand Up @@ -220,6 +220,7 @@ func TestCallMetrics(t *testing.T) {
"clientHTTPMethod": "POST",
"Client-Req-Header-X-Client-Id": "bar",
"Client-Req-Header-Content-Type": "application/json",
"Client-Req-Header-Accept": "application/json",
"Client-Res-Header-Content-Type": "text/plain; charset=utf-8",

"zone": "unknown",
Expand Down

0 comments on commit e670e4d

Please sign in to comment.