Skip to content

Commit

Permalink
Set Content-Type to "application/json" where applicable in API
Browse files Browse the repository at this point in the history
  • Loading branch information
SHyx0rmZ committed Apr 18, 2018
1 parent bd7423f commit 84e8772
Show file tree
Hide file tree
Showing 19 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/buildserver/create.go
Expand Up @@ -38,6 +38,7 @@ func (s *Server) CreateBuild(team db.Team) http.Handler {

go engineBuild.Resume(hLog)

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)

err = json.NewEncoder(w).Encode(present.Build(build))
Expand Down
1 change: 1 addition & 0 deletions api/buildserver/get.go
Expand Up @@ -12,6 +12,7 @@ func (s *Server) GetBuild(build db.Build) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
logger := s.logger.Session("get-build")

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)

err := json.NewEncoder(w).Encode(present.Build(build))
Expand Down
1 change: 1 addition & 0 deletions api/buildserver/plan.go
Expand Up @@ -12,6 +12,7 @@ func (s *Server) GetBuildPlan(build db.Build) http.Handler {
hLog := s.logger.Session("get-build-plan")

return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
err := json.NewEncoder(w).Encode(atc.PublicBuildPlan{
Schema: build.Engine(),
Plan: build.PublicPlan(),
Expand Down
1 change: 1 addition & 0 deletions api/buildserver/preparation.go
Expand Up @@ -25,6 +25,7 @@ func (s *Server) GetBuildPreparation(build db.Build) http.Handler {
return
}

w.Header().Set("Content-Type", "application/json")
err = json.NewEncoder(w).Encode(present.BuildPreparation(prep))
if err != nil {
logger.Error("failed-to-encode-build-preparation", err)
Expand Down
1 change: 1 addition & 0 deletions api/buildserver/resources.go
Expand Up @@ -36,6 +36,7 @@ func (s *Server) BuildResources(build db.Build) http.Handler {
Outputs: atcOutputs,
}

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
err = json.NewEncoder(w).Encode(output)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions api/configserver/get.go
Expand Up @@ -78,6 +78,7 @@ func (s *Server) GetConfig(w http.ResponseWriter, r *http.Request) {
}

w.Header().Set(atc.ConfigVersionHeader, fmt.Sprintf("%d", pipeline.ConfigVersion()))
w.Header().Set("Content-Type", "application/json")

err = json.NewEncoder(w).Encode(atc.ConfigResponse{
Config: &config,
Expand Down
2 changes: 2 additions & 0 deletions api/configserver/save.go
Expand Up @@ -134,6 +134,8 @@ func (s *Server) SaveConfig(w http.ResponseWriter, r *http.Request) {

session.Info("saved")

w.Header().Set("Content-Type", "application/json")

if created {
w.WriteHeader(http.StatusCreated)
} else {
Expand Down
1 change: 1 addition & 0 deletions api/infoserver/info.go
Expand Up @@ -10,6 +10,7 @@ import (
func (s *Server) Info(w http.ResponseWriter, r *http.Request) {
logger := s.logger.Session("info")

w.Header().Set("Content-Type", "application/json")
err := json.NewEncoder(w).Encode(atc.Info{Version: s.version, WorkerVersion: s.workerVersion})
if err != nil {
logger.Error("failed-to-encode-info", err)
Expand Down
1 change: 1 addition & 0 deletions api/jobserver/get.go
Expand Up @@ -34,6 +34,7 @@ func (s *Server) GetJob(pipeline db.Pipeline) http.Handler {

teamName := r.FormValue(":team_name")

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)

err = json.NewEncoder(w).Encode(present.Job(
Expand Down
1 change: 1 addition & 0 deletions api/jobserver/get_build.go
Expand Up @@ -38,6 +38,7 @@ func (s *Server) GetJobBuild(pipeline db.Pipeline) http.Handler {
return
}

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)

err = json.NewEncoder(w).Encode(present.Build(build))
Expand Down
1 change: 1 addition & 0 deletions api/jobserver/list_inputs.go
Expand Up @@ -71,6 +71,7 @@ func (s *Server) ListJobInputs(pipeline db.Pipeline) http.Handler {
presentedBuildInputs[i] = present.BuildInput(input, config, resource.Source())
}

w.Header().Set("Content-Type", "application/json")
err = json.NewEncoder(w).Encode(presentedBuildInputs)
if err != nil {
logger.Error("failed-to-encode-build-inputs", err)
Expand Down
1 change: 1 addition & 0 deletions api/pipelineserver/build.go
Expand Up @@ -38,6 +38,7 @@ func (s *Server) CreateBuild(pipelineDB db.Pipeline) http.Handler {

go engineBuild.Resume(logger)

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)

err = json.NewEncoder(w).Encode(present.Build(build))
Expand Down
1 change: 1 addition & 0 deletions api/resourceserver/get.go
Expand Up @@ -36,6 +36,7 @@ func (s *Server) GetResource(pipeline db.Pipeline) http.Handler {
teamName,
)

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)

err = json.NewEncoder(w).Encode(resource)
Expand Down
1 change: 1 addition & 0 deletions api/resourceserver/list.go
Expand Up @@ -37,6 +37,7 @@ func (s *Server) ListResources(pipeline db.Pipeline) http.Handler {
)
}

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
err = json.NewEncoder(w).Encode(presentedResources)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions api/teamserver/list.go
Expand Up @@ -23,6 +23,7 @@ func (s *Server) ListTeams(w http.ResponseWriter, r *http.Request) {
presentedTeams[i] = present.Team(team)
}

w.Header().Set("Content-Type", "application/json")
err = json.NewEncoder(w).Encode(presentedTeams)
if err != nil {
hLog.Error("failed-to-encode-teams", err)
Expand Down
2 changes: 2 additions & 0 deletions api/teamserver/set.go
Expand Up @@ -91,6 +91,7 @@ func (s *Server) SetTeam(w http.ResponseWriter, r *http.Request) {
return
}

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
} else if acc.IsAdmin() {
hLog.Debug("creating team")
Expand All @@ -101,6 +102,7 @@ func (s *Server) SetTeam(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusCreated)
} else {
w.WriteHeader(http.StatusForbidden)
Expand Down
1 change: 1 addition & 0 deletions api/volumeserver/list.go
Expand Up @@ -35,6 +35,7 @@ func (s *Server) ListVolumes(team db.Team) http.Handler {
}
}

w.Header().Set("Content-Type", "application/json")
err = json.NewEncoder(w).Encode(presentedVolumes)
if err != nil {
hLog.Error("failed-to-encode-volumes", err)
Expand Down
1 change: 1 addition & 0 deletions api/workerserver/heartbeat.go
Expand Up @@ -64,6 +64,7 @@ func (s *Server) HeartbeatWorker(w http.ResponseWriter, r *http.Request) {
return
}

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
err = json.NewEncoder(w).Encode(present.Worker(savedWorker))
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions api/workerserver/list.go
Expand Up @@ -29,6 +29,7 @@ func (s *Server) ListWorkers(w http.ResponseWriter, r *http.Request) {
atcWorkers[i] = present.Worker(savedWorker)
}

w.Header().Set("Content-Type", "application/json")
err = json.NewEncoder(w).Encode(atcWorkers)
if err != nil {
logger.Error("failed-to-encode-workers", err)
Expand Down

0 comments on commit 84e8772

Please sign in to comment.