Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
Moved adding the Content-Type header from sendOSBRequest() to newOSBR…
Browse files Browse the repository at this point in the history
…equest() (#611)

Bind requests did not include the Content-Type: application/json header. Since all OSB requests (that include a body) should use this content-type, I've moved it to newOSBRequest().
  • Loading branch information
luksa authored and arschles committed Mar 28, 2017
1 parent 8395341 commit 622d930
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions pkg/brokerapi/openservicebroker/open_service_broker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,8 +331,6 @@ func sendOSBRequest(c *openServiceBrokerClient, method string, url string, objec
return nil, fmt.Errorf("Failed to create request object: %s", err.Error())
}

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

resp, err := c.Do(req)
if err != nil {
return nil, fmt.Errorf("Failed to send request: %s", err.Error())
Expand All @@ -346,6 +344,9 @@ func (c *openServiceBrokerClient) newOSBRequest(method, urlStr string, body io.R
if err != nil {
return nil, err
}
if body != nil {
req.Header.Set("Content-Type", "application/json")
}
req.Header.Add(constants.APIVersionHeader, constants.APIVersion)
req.SetBasicAuth(c.username, c.password)
return req, nil
Expand Down
11 changes: 11 additions & 0 deletions pkg/brokerapi/openservicebroker/open_service_broker_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ func TestProvisionInstanceCreated(t *testing.T) {
if _, err := c.CreateServiceInstance(testServiceInstanceID, &brokerapi.CreateServiceInstanceRequest{}); err != nil {
t.Fatal(err.Error())
}

verifyRequestContentType(fbs.Request, t)
}

func TestProvisionInstanceOK(t *testing.T) {
Expand Down Expand Up @@ -251,6 +253,8 @@ func TestBindOk(t *testing.T) {
if fbs.RequestObject == nil {
t.Fatalf("BindingRequest was not received correctly")
}
verifyRequestContentType(fbs.Request, t)

actual := reflect.TypeOf(fbs.RequestObject)
expected := reflect.TypeOf(&brokerapi.BindingRequest{})
if actual != expected {
Expand Down Expand Up @@ -338,3 +342,10 @@ func verifyBindingMethodAndPath(method, serviceID, bindingID string, req *http.R
}

}

func verifyRequestContentType(req *http.Request, t *testing.T) {
contentType := req.Header.Get("Content-Type")
if contentType != "application/json" {
t.Fatalf("Expected the request content-type to be application/json, but was %s", contentType)
}
}
1 change: 1 addition & 0 deletions pkg/brokerapi/openservicebroker/util/fake_broker_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ func (f *FakeBrokerServer) lastOperationHandler(w http.ResponseWriter, r *http.R

func (f *FakeBrokerServer) provisionHandler(w http.ResponseWriter, r *http.Request) {
glog.Info("fake provision called")
f.Request = r
req := &brokerapi.CreateServiceInstanceRequest{}
if err := util.BodyToObject(r, req); err != nil {
w.WriteHeader(http.StatusBadRequest)
Expand Down

0 comments on commit 622d930

Please sign in to comment.