Skip to content

Commit

Permalink
Merge branch 'hotfix-v0.10.3' of github.com:Peripli/service-manager i…
Browse files Browse the repository at this point in the history
…nto hotfix-v0.10.3
  • Loading branch information
Nikolay Stoykov committed Mar 9, 2020
2 parents 1f706db + 2612ed1 commit 18734c2
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ func New(ctx context.Context, e env.Environment, options *Options) (*web.API, er
// Default filters - more filters can be registered using the relevant API methods
Filters: []web.Filter{
&filters.Logging{},
&filters.SupportedEncodingsFilter{},
&filters.SelectionCriteria{},
filters.NewProtectedLabelsFilter(options.APISettings.ProtectedLabels),
&filters.ProtectedSMPlatformFilter{},
Expand Down
48 changes: 48 additions & 0 deletions api/filters/supported_encodings_filter.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2018 The Service Manager Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package filters

import (
"github.com/Peripli/service-manager/pkg/web"
)

const (
SupportedEncodingsFilterName = "SupportedEncodingsFilter"
)

type SupportedEncodingsFilter struct {
}

func (*SupportedEncodingsFilter) Name() string {
return SupportedEncodingsFilterName
}

/** Allow to proxy only SM supported osb encodings (Identity/none are currently allowed) */
func (l *SupportedEncodingsFilter) Run(req *web.Request, next web.Handler) (*web.Response, error) {
req.Header.Del("Accept-Encoding")
return next.Handle(req)
}

func (*SupportedEncodingsFilter) FilterMatchers() []web.FilterMatcher {
return []web.FilterMatcher{
{
Matchers: []web.Matcher{
web.Path(web.OSBURL + "/**"),
},
},
}
}
7 changes: 7 additions & 0 deletions test/osb_test/bind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ var _ = Describe("Bind", func() {
ctx.SMWithBasic.PUT(smBrokerURL+"/v2/service_instances/iid/service_bindings/bid").WithHeader(brokerAPIVersionHeaderKey, brokerAPIVersionHeaderValue).
WithJSON(provisionRequestBodyMap()()).Expect().Status(http.StatusCreated)
})

It("Binding to a server that supports gzip encoded responses", func() {
brokerServer.BindingHandler = gzipHandler(http.StatusCreated, `{}`)
ctx.SMWithBasic.PUT(smBrokerURL+"/v2/service_instances/iid/service_bindings/bid").WithHeader(brokerAPIVersionHeaderKey, brokerAPIVersionHeaderValue).
WithJSON(provisionRequestBodyMap()()).Expect().Status(http.StatusCreated)
})

})

Context("when call to failing service broker", func() {
Expand Down
27 changes: 27 additions & 0 deletions test/osb_test/osb_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
package osb_test

import (
"bytes"
"compress/gzip"
"context"
"encoding/json"
"fmt"
"io"
"net/http"
"strings"
"testing"
Expand Down Expand Up @@ -201,6 +204,30 @@ func parameterizedHandler(statusCode int, responseBody string) func(rw http.Resp
}
}

func gzipWrite(w io.Writer, data []byte) error {
// Write gzipped data to the client
gw, err := gzip.NewWriterLevel(w, gzip.BestSpeed)
defer gw.Close()
gw.Write(data)
return err
}

func gzipHandler(statusCode int, responseBody string) func(rw http.ResponseWriter, _ *http.Request) {
return func(rw http.ResponseWriter, req *http.Request) {
if req.Header.Get("Accept-Encoding") == "gzip" {
rw.Header().Set("Content-Encoding", "gzip")
rw.WriteHeader(statusCode)
var buf bytes.Buffer
gzipWrite(&buf, []byte(responseBody))
rw.Write(buf.Bytes())
} else {
rw.Header().Set("Content-Type", "application/json")
rw.WriteHeader(statusCode)
rw.Write([]byte(responseBody))
}
}
}

func queryParameterVerificationHandler(key, value string) http.HandlerFunc {
return func(writer http.ResponseWriter, request *http.Request) {
defer GinkgoRecover()
Expand Down

0 comments on commit 18734c2

Please sign in to comment.