Skip to content

Commit

Permalink
go get knative.dev/[email protected] (#602)
Browse files Browse the repository at this point in the history
go mod vendor
make generate-release

Signed-off-by: Calum Murray <[email protected]>
  • Loading branch information
Cali0707 authored May 6, 2024
1 parent 7fddc6b commit e64d6af
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ require (
knative.dev/hack v0.0.0-20240404013450-1133b37da8d7
knative.dev/hack/schema v0.0.0-20240404013450-1133b37da8d7
knative.dev/pkg v0.0.0-20240416145024-0f34a8815650
knative.dev/reconciler-test v0.0.0-20240417065737-ca905cbb09a9
knative.dev/reconciler-test v0.0.0-20240503125949-8fd5ae6217a3
sigs.k8s.io/yaml v1.4.0
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -891,8 +891,8 @@ knative.dev/hack/schema v0.0.0-20240404013450-1133b37da8d7 h1:MyFPlm1NkiCF7H8nKw
knative.dev/hack/schema v0.0.0-20240404013450-1133b37da8d7/go.mod h1:3pWwBLnTZSM9psSgCAvhKOHIPTzqfEMlWRpDu6IYhK0=
knative.dev/pkg v0.0.0-20240416145024-0f34a8815650 h1:m2ahFUO0L2VrgGDYdyOUFdE6xBd3pLXAJozLJwqLRQM=
knative.dev/pkg v0.0.0-20240416145024-0f34a8815650/go.mod h1:soFw5ss08G4PU3JiFDKqiZRd2U7xoqcfNpJP1coIXkY=
knative.dev/reconciler-test v0.0.0-20240417065737-ca905cbb09a9 h1:AuQT+6OU8R7QIMNBtViewLG6mkMbNlUwumy4gukpprc=
knative.dev/reconciler-test v0.0.0-20240417065737-ca905cbb09a9/go.mod h1:xrX67/nfPlCu0UAt9OHCpI1ZlAF0rqLA5hZrB/xu63s=
knative.dev/reconciler-test v0.0.0-20240503125949-8fd5ae6217a3 h1:kndnO/h0hG+M/sVqGysZHL9P4qXHzQ7ZmgzKXk0k8fg=
knative.dev/reconciler-test v0.0.0-20240503125949-8fd5ae6217a3/go.mod h1:xrX67/nfPlCu0UAt9OHCpI1ZlAF0rqLA5hZrB/xu63s=
pgregory.net/rapid v1.1.0 h1:CMa0sjHSru3puNx+J0MIAuiiEV4N0qj8/cMWGBBCsjw=
pgregory.net/rapid v1.1.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@ limitations under the License.
package forwarder

import (
"bytes"
"context"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
"time"

cloudevents "github.com/cloudevents/sdk-go/v2"
"github.com/cloudevents/sdk-go/v2/binding"
cloudeventsbindings "github.com/cloudevents/sdk-go/v2/binding"
"go.opencensus.io/trace"
"go.uber.org/zap"
Expand Down Expand Up @@ -127,10 +128,21 @@ func (o *Forwarder) ServeHTTP(writer http.ResponseWriter, request *http.Request)
requestCtx, span := trace.StartSpan(request.Context(), "eventshub-forwarder")
defer span.End()

body, err := io.ReadAll(request.Body)
if err != nil {
writer.WriteHeader(http.StatusInternalServerError)
logging.FromContext(o.ctx).Errorw("Failed to read request body", zap.Error(err))
return
}
_ = request.Body.Close()
request.Body = io.NopCloser(bytes.NewBuffer(body))

m := cloudeventshttp.NewMessageFromHttpRequest(request)
defer m.Finish(nil)

event, eventErr := cloudeventsbindings.ToEvent(context.TODO(), m)
request.Body = io.NopCloser(bytes.NewBuffer(body)) // reset body

receivedHeaders := make(http.Header)
for k, v := range request.Header {
if !strings.HasPrefix(k, "Ce-") {
Expand Down Expand Up @@ -174,11 +186,6 @@ func (o *Forwarder) ServeHTTP(writer http.ResponseWriter, request *http.Request)
}
req.URL = u

err = cehttp.WriteRequest(requestCtx, binding.ToMessage(event), req)
if err != nil {
logging.FromContext(o.ctx).Error("Cannot write the event to request: ", err)
}

eventString := "unknown"
if event != nil {
eventString = event.String()
Expand All @@ -202,7 +209,7 @@ func (o *Forwarder) ServeHTTP(writer http.ResponseWriter, request *http.Request)
}
}

writer.WriteHeader(http.StatusAccepted)
writer.WriteHeader(res.StatusCode)
}

func (o *Forwarder) sentInfo(event *cloudevents.Event, req *http.Request, err error) eventshub.EventInfo {
Expand Down
2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1381,7 +1381,7 @@ knative.dev/pkg/webhook/resourcesemantics
knative.dev/pkg/webhook/resourcesemantics/conversion
knative.dev/pkg/webhook/resourcesemantics/defaulting
knative.dev/pkg/webhook/resourcesemantics/validation
# knative.dev/reconciler-test v0.0.0-20240417065737-ca905cbb09a9
# knative.dev/reconciler-test v0.0.0-20240503125949-8fd5ae6217a3
## explicit; go 1.21
knative.dev/reconciler-test/cmd/eventshub
knative.dev/reconciler-test/pkg/environment
Expand Down

0 comments on commit e64d6af

Please sign in to comment.