Repository: cloudevents/sdk-go
Pull request #374 (2020-03-12 15:07:31)

Prune WriteHttpRequest
Reusing these tests for `WriteHttpRequestWriter`


Patch:
diff --git a/alias.go b/alias.go
index 48cd439..e39506e 100644
--- a/alias.go
+++ b/alias.go
@@ -31,7 +31,6 @@ type EventContextV03 = event.EventContextV03
 // Custom Types
 
 type Timestamp = types.Timestamp
-type URLRef = types.URLRef
 type URIRef = types.URIRef
 
 // HTTP Protocol
@@ -103,7 +102,6 @@ var (
 	// Custom Types
 
 	ParseTimestamp = types.ParseTimestamp
-	ParseURLRef    = types.ParseURLRef
 	ParseURIRef    = types.ParseURIRef
 	ParseURI       = types.ParseURI
 
diff --git a/cmd/samples/amqp/sender/main.go b/cmd/samples/amqp/sender/main.go
index c6cb25d..ce7672f 100644
--- a/cmd/samples/amqp/sender/main.go
+++ b/cmd/samples/amqp/sender/main.go
@@ -96,7 +96,7 @@ func main() {
 			ID:              uuid.New().String(),
 			Type:            "com.cloudevents.sample.sent",
 			Time:            &types.Timestamp{Time: now},
-			Source:          types.URLRef{URL: d.Source},
+			Source:          types.URIRef{URL: d.Source},
 			DataContentType: &contentType,
 		}.AsV03()
 		if err := d.Send(ctx, seq); err != nil {
diff --git a/cmd/samples/http/requester-with-custom-client/main.go b/cmd/samples/http/requester-with-custom-client/main.go
index 75e1ec0..d263a22 100644
--- a/cmd/samples/http/requester-with-custom-client/main.go
+++ b/cmd/samples/http/requester-with-custom-client/main.go
@@ -109,7 +109,7 @@ func _main(args []string, env envConfig) int {
 					Context: cloudevents.EventContextV03{
 						ID:              uuid.New().String(),
 						Type:            "com.cloudevents.sample.sent",
-						Source:          cloudevents.URLRef{URL: *source},
+						Source:          cloudevents.URIRef{URL: *source},
 						DataContentType: &dataContentType,
 					}.AsV03(),
 					Data: &Example{
diff --git a/pkg/event/eventcontext_v03.go b/pkg/event/eventcontext_v03.go
index 6cb1373..1d618e8 100644
--- a/pkg/event/eventcontext_v03.go
+++ b/pkg/event/eventcontext_v03.go
@@ -22,7 +22,7 @@ type EventContextV03 struct {
 	// Type - The type of the occurrence which has happened.
 	Type string `json:"type"`
 	// Source - A URI describing the event producer.
-	Source types.URLRef `json:"source"`
+	Source types.URIRef `json:"source"`
 	// Subject - The subject of the event in the context of the event producer
 	// (identified by `source`).
 	Subject *string `json:"subject,omitempty"`
@@ -31,7 +31,7 @@ type EventContextV03 struct {
 	// Time - A Timestamp when the event happened.
 	Time *types.Timestamp `json:"time,omitempty"`
 	// DataSchema - A link to the schema that the `data` attribute adheres to.
-	SchemaURL *types.URLRef `json:"schemaurl,omitempty"`
+	SchemaURL *types.URIRef `json:"schemaurl,omitempty"`
 	// GetDataMediaType - A MIME (RFC2046) string describing the media type of `data`.
 	// TODO: Should an empty string assume `application/json`, `application/octet-stream`, or auto-detect the content?
 	DataContentType *string `json:"datacontenttype,omitempty"`
@@ -98,12 +98,12 @@ func (ec *EventContextV03) SetExtension(name string, value interface{}) error {
 // Clone implements EventContextConverter.Clone
 func (ec EventContextV03) Clone() EventContext {
 	ec03 := ec.AsV03()
-	ec03.Source = types.Clone(ec.Source).(types.URLRef)
+	ec03.Source = types.Clone(ec.Source).(types.URIRef)
 	if ec.Time != nil {
 		ec03.Time = types.Clone(ec.Time).(*types.Timestamp)
 	}
 	if ec.SchemaURL != nil {
-		ec03.SchemaURL = types.Clone(ec.SchemaURL).(*types.URLRef)
+		ec03.SchemaURL = types.Clone(ec.SchemaURL).(*types.URIRef)
 	}
 	ec03.Extensions = ec.cloneExtensions()
 	return ec03
diff --git a/pkg/event/eventcontext_v03_writer.go b/pkg/event/eventcontext_v03_writer.go
index 5fe8122..d69dfd2 100644
--- a/pkg/event/eventcontext_v03_writer.go
+++ b/pkg/event/eventcontext_v03_writer.go
@@ -46,7 +46,7 @@ func (ec *EventContextV03) SetSource(u string) error {
 	if err != nil {
 		return err
 	}
-	ec.Source = types.URLRef{URL: *pu}
+	ec.Source = types.URIRef{URL: *pu}
 	return nil
 }
 
@@ -92,7 +92,7 @@ func (ec *EventContextV03) SetDataSchema(u string) error {
 	if err != nil {
 		return err
 	}
-	ec.SchemaURL = &types.URLRef{URL: *pu}
+	ec.SchemaURL = &types.URIRef{URL: *pu}
 	return nil
 }
 
diff --git a/pkg/event/eventcontext_v1.go b/pkg/event/eventcontext_v1.go
index b8b065e..2ca2b50 100644
--- a/pkg/event/eventcontext_v1.go
+++ b/pkg/event/eventcontext_v1.go
@@ -132,13 +132,13 @@ func (ec EventContextV1) AsV03() *EventContextV03 {
 		Time:            ec.Time,
 		Type:            ec.Type,
 		DataContentType: ec.DataContentType,
-		Source:          types.URLRef{URL: ec.Source.URL},
+		Source:          types.URIRef{URL: ec.Source.URL},
 		Subject:         ec.Subject,
 		Extensions:      make(map[string]interface{}),
 	}
 
 	if ec.DataSchema != nil {
-		ret.SchemaURL = &types.URLRef{URL: ec.DataSchema.URL}
+		ret.SchemaURL = &types.URIRef{URL: ec.DataSchema.URL}
 	}
 
 	// TODO: DeprecatedDataContentEncoding needs to be moved to extensions.
diff --git a/pkg/transport/amqp/types.go b/pkg/transport/amqp/types.go
index d5fe788..7cc4ec7 100644
--- a/pkg/transport/amqp/types.go
+++ b/pkg/transport/amqp/types.go
@@ -12,8 +12,6 @@ func safeAMQPPropertiesUnwrap(val interface{}) (interface{}, error) {
 		v = t.String()
 	case types.URIRef: // Use string form of URLs.
 		v = t.String()
-	case types.URLRef: // Use string form of URLs.
-		v = t.String()
 	case types.Timestamp: // Use string form of URLs.
 		v = t.Time
 	case int32: // Use AMQP long for Integer as per CE spec.
diff --git a/pkg/transport/http/message_write_response.go b/pkg/transport/http/message_write_response.go
deleted file mode 100644
index 267ed1d..0000000
--- a/pkg/transport/http/message_write_response.go
+++ /dev/null
@@ -1,78 +0,0 @@
-package http
-
-import (
-	"context"
-	"io"
-	"io/ioutil"
-	"net/http"
-
-	"github.com/cloudevents/sdk-go/pkg/binding"
-	"github.com/cloudevents/sdk-go/pkg/binding/format"
-	"github.com/cloudevents/sdk-go/pkg/binding/spec"
-	"github.com/cloudevents/sdk-go/pkg/types"
-)
-
-// Fill the provided httpResponse with the message m.
-// Using context you can tweak the encoding processing (more details on binding.Write documentation).
-func WriteResponse(ctx context.Context, m binding.Message, httpResponse *http.Response, transformers binding.TransformerFactories) error {
-	structuredWriter := (*httpResponseWriter)(httpResponse)
-	binaryWriter := (*httpResponseWriter)(httpResponse)
-
-	_, err := binding.Write(
-		ctx,
-		m,
-		structuredWriter,
-		binaryWriter,
-		transformers,
-	)
-	return err
-}
-
-type httpResponseWriter http.Response
-
-func (b *httpResponseWriter) SetStructuredEvent(ctx context.Context, format format.Format, event io.Reader) error {
-	b.Header.Set(ContentType, format.MediaType())
-	b.Body = ioutil.NopCloser(event)
-	return nil
-}
-
-func (b *httpResponseWriter) Start(ctx context.Context) error {
-	return nil
-}
-
-func (b *httpResponseWriter) End() error {
-	return nil
-}
-
-func (b *httpResponseWriter) SetData(reader io.Reader) error {
-	b.Body = ioutil.NopCloser(reader)
-	return nil
-}
-
-func (b *httpResponseWriter) SetAttribute(attribute spec.Attribute, value interface{}) error {
-	// Http headers, everything is a string!
-	s, err := types.Format(value)
-	if err != nil {
-		return err
-	}
-
-	if attribute.Kind() == spec.DataContentType {
-		b.Header.Add(ContentType, s)
-	} else {
-		b.Header.Add(prefix+attribute.Name(), s)
-	}
-	return nil
-}
-
-func (b *httpResponseWriter) SetExtension(name string, value interface{}) error {
-	// Http headers, everything is a string!
-	s, err := types.Format(value)
-	if err != nil {
-		return err
-	}
-	b.Header.Add(prefix+name, s)
-	return nil
-}
-
-var _ binding.StructuredWriter = (*httpResponseWriter)(nil) // Test it conforms to the interface
-var _ binding.BinaryWriter = (*httpResponseWriter)(nil)     // Test it conforms to the interface
diff --git a/pkg/transport/http/message_write_responsewriter.go b/pkg/transport/http/message_write_responsewriter.go
index 6056385..c9f90b7 100644
--- a/pkg/transport/http/message_write_responsewriter.go
+++ b/pkg/transport/http/message_write_responsewriter.go
@@ -3,7 +3,6 @@ package http
 import (
 	"context"
 	"io"
-	"io/ioutil"
 	"net/http"
 	"strconv"
 
@@ -19,7 +18,7 @@ func WriteResponseWriter(ctx context.Context, m binding.Message, status int, rw
 	if status < 200 || status >= 600 {
 		status = http.StatusOK
 	}
-	writer := &httpResponseWriterEncoder{rw: rw, status: status}
+	writer := &httpResponseWriter{rw: rw, status: status}
 
 	_, err := binding.Write(
 		ctx,
@@ -31,39 +30,38 @@ func WriteResponseWriter(ctx context.Context, m binding.Message, status int, rw
 	return err
 }
 
-type httpResponseWriterEncoder struct {
+type httpResponseWriter struct {
 	rw     http.ResponseWriter
 	status int
 }
 
-func (b *httpResponseWriterEncoder) SetStructuredEvent(ctx context.Context, format format.Format, event io.Reader) error {
+func (b *httpResponseWriter) SetStructuredEvent(ctx context.Context, format format.Format, event io.Reader) error {
 	b.rw.Header().Set(ContentType, format.MediaType())
 	return b.SetData(event)
 }
 
-func (b *httpResponseWriterEncoder) Start(ctx context.Context) error {
+func (b *httpResponseWriter) Start(ctx context.Context) error {
 	return nil
 }
 
-func (b *httpResponseWriterEncoder) End() error {
+func (b *httpResponseWriter) End() error {
 	return nil
 }
 
-func (b *httpResponseWriterEncoder) SetData(reader io.Reader) error {
+func (b *httpResponseWriter) SetData(reader io.Reader) error {
 	// Finalize the headers.
 	b.rw.WriteHeader(b.status)
 
 	// Write body.
-	body, err := ioutil.ReadAll(reader)
+	copied, err := io.Copy(b.rw, reader)
 	if err != nil {
 		return err
 	}
-	n, err := b.rw.Write(body)
-	b.rw.Header().Set(ContentLength, strconv.Itoa(n))
+	b.rw.Header().Set("Content-Length", strconv.FormatInt(copied, 10))
 	return nil
 }
 
-func (b *httpResponseWriterEncoder) SetAttribute(attribute spec.Attribute, value interface{}) error {
+func (b *httpResponseWriter) SetAttribute(attribute spec.Attribute, value interface{}) error {
 	// Http headers, everything is a string!
 	s, err := types.Format(value)
 	if err != nil {
@@ -78,7 +76,7 @@ func (b *httpResponseWriterEncoder) SetAttribute(attribute spec.Attribute, value
 	return nil
 }
 
-func (b *httpResponseWriterEncoder) SetExtension(name string, value interface{}) error {
+func (b *httpResponseWriter) SetExtension(name string, value interface{}) error {
 	// Http headers, everything is a string!
 	s, err := types.Format(value)
 	if err != nil {
diff --git a/pkg/types/urlref.go b/pkg/types/urlref.go
deleted file mode 100644
index 2578801..0000000
--- a/pkg/types/urlref.go
+++ /dev/null
@@ -1,79 +0,0 @@
-package types
-
-import (
-	"encoding/json"
-	"encoding/xml"
-	"fmt"
-	"net/url"
-)
-
-// URLRef is a wrapper to url.URL. It is intended to enforce compliance with
-// the CloudEvents spec for their definition of URI-Reference. Custom
-// marshal methods are implemented to ensure the outbound URLRef object is
-// is a flat string.
-//
-// deprecated: use URIRef.
-type URLRef struct {
-	url.URL
-}
-
-// ParseURLRef attempts to parse the given string as a URI-Reference.
-func ParseURLRef(u string) *URLRef {
-	if u == "" {
-		return nil
-	}
-	pu, err := url.Parse(u)
-	if err != nil {
-		return nil
-	}
-	return &URLRef{URL: *pu}
-}
-
-// MarshalJSON implements a custom json marshal method used when this type is
-// marshaled using json.Marshal.
-func (u URLRef) MarshalJSON() ([]byte, error) {
-	b := fmt.Sprintf("%q", u.String())
-	return []byte(b), nil
-}
-
-// UnmarshalJSON implements the json unmarshal method used when this type is
-// unmarshaled using json.Unmarshal.
-func (u *URLRef) UnmarshalJSON(b []byte) error {
-	var ref string
-	if err := json.Unmarshal(b, &ref); err != nil {
-		return err
-	}
-	r := ParseURLRef(ref)
-	if r != nil {
-		*u = *r
-	}
-	return nil
-}
-
-// MarshalXML implements a custom xml marshal method used when this type is
-// marshaled using xml.Marshal.
-func (u URLRef) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
-	return e.EncodeElement(u.String(), start)
-}
-
-// UnmarshalXML implements the xml unmarshal method used when this type is
-// unmarshaled using xml.Unmarshal.
-func (u *URLRef) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
-	var ref string
-	if err := d.DecodeElement(&ref, &start); err != nil {
-		return err
-	}
-	r := ParseURLRef(ref)
-	if r != nil {
-		*u = *r
-	}
-	return nil
-}
-
-// String returns the full string representation of the URI-Reference.
-func (u *URLRef) String() string {
-	if u == nil {
-		return ""
-	}
-	return u.URL.String()
-}
diff --git a/pkg/types/value.go b/pkg/types/value.go
index 89892ff..f220f23 100644
--- a/pkg/types/value.go
+++ b/pkg/types/value.go
@@ -117,9 +117,6 @@ func Validate(v interface{}) (interface{}, error) {
 		return v, nil
 	case URI:
 		return v, nil
-	case URLRef:
-		// Convert old type to new one
-		return URIRef{v.URL}, nil
 	case time.Time:
 		return Timestamp{v}, nil
 	case *time.Time:
@@ -165,10 +162,6 @@ func Clone(v interface{}) interface{} {
 		return v
 	case *URI:
 		return &URI{v.URL}
-	case URLRef:
-		return URLRef{v.URL}
-	case *URLRef:
-		return &URLRef{v.URL}
 	case time.Time:
 		return Timestamp{v}
 	case *time.Time:


Test patch:
diff --git a/pkg/binding/format/format_test.go b/pkg/binding/format/format_test.go
index 23d6d71..739f73e 100644
--- a/pkg/binding/format/format_test.go
+++ b/pkg/binding/format/format_test.go
@@ -16,7 +16,7 @@ func TestJSON(t *testing.T) {
 		Context: event.EventContextV03{
 			Type:   "type",
 			ID:     "id",
-			Source: *types.ParseURLRef("source"),
+			Source: *types.ParseURIRef("source"),
 		}.AsV03(),
 	}
 	e.SetExtension("ex", "val")
@@ -45,7 +45,7 @@ func TestMarshalUnmarshal(t *testing.T) {
 		Context: event.EventContextV03{
 			Type:   "type",
 			ID:     "id",
-			Source: *types.ParseURLRef("source"),
+			Source: *types.ParseURIRef("source"),
 		}.AsV03(),
 	}
 	assert.NoError(e.SetData("foo"))
diff --git a/pkg/binding/transformer/version_test.go b/pkg/binding/transformer/version_test.go
index 9f0f807..b7d4dd2 100644
--- a/pkg/binding/transformer/version_test.go
+++ b/pkg/binding/transformer/version_test.go
@@ -17,7 +17,7 @@ import (
 func TestVersionTranscoder(t *testing.T) {
 	var testEventV03 = event.Event{
 		Context: event.EventContextV03{
-			Source:          types.URLRef{URL: url.URL{Path: "source"}},
+			Source:          types.URIRef{URL: url.URL{Path: "source"}},
 			DataContentType: event.StringOfApplicationJSON(),
 			ID:              "id",
 			Type:            "type",
diff --git a/pkg/client/client_test.go b/pkg/client/client_test.go
index b1d7f5c..de86b7f 100644
--- a/pkg/client/client_test.go
+++ b/pkg/client/client_test.go
@@ -114,7 +114,7 @@ func TestClientSend(t *testing.T) {
 			event: event.Event{
 				Context: event.EventContextV03{
 					Type:   "unit.test.client",
-					Source: *types.ParseURLRef("/unit/test/client"),
+					Source: *types.ParseURIRef("/unit/test/client"),
 					Time:   &types.Timestamp{Time: now},
 					ID:     "AABBCCDDEE",
 				}.AsV03(),
@@ -142,7 +142,7 @@ func TestClientSend(t *testing.T) {
 			event: event.Event{
 				Context: event.EventContextV03{
 					Type:   "unit.test.client",
-					Source: *types.ParseURLRef("/unit/test/client"),
+					Source: *types.ParseURIRef("/unit/test/client"),
 					Time:   &types.Timestamp{Time: now},
 					ID:     "AABBCCDDEE",
 				}.AsV03(),
@@ -347,7 +347,7 @@ func TestClientReceive(t *testing.T) {
 				Context: event.EventContextV03{
 					Type:            "unit.test.client",
 					DataContentType: event.StringOfApplicationJSON(),
-					Source:          *types.ParseURLRef("/unit/test/client"),
+					Source:          *types.ParseURIRef("/unit/test/client"),
 					Time:            &types.Timestamp{Time: now},
 					ID:              "AABBCCDDEE",
 				}.AsV03(),
@@ -371,7 +371,7 @@ func TestClientReceive(t *testing.T) {
 				Context: event.EventContextV03{
 					Type:            "unit.test.client",
 					DataContentType: event.StringOfApplicationJSON(),
-					Source:          *types.ParseURLRef("/unit/test/client"),
+					Source:          *types.ParseURIRef("/unit/test/client"),
 					Time:            &types.Timestamp{Time: now},
 					ID:              "AABBCCDDEE",
 				}.AsV03(),
@@ -502,7 +502,7 @@ func TestTracedClientReceive(t *testing.T) {
 				Context: event.EventContextV03{
 					Type:            "unit.test.client",
 					DataContentType: event.StringOfApplicationJSON(),
-					Source:          *types.ParseURLRef("/unit/test/client"),
+					Source:          *types.ParseURIRef("/unit/test/client"),
 					Time:            &types.Timestamp{Time: now},
 					ID:              "AABBCCDDEE",
 				}.AsV03(),
diff --git a/pkg/event/event_marshal_test.go b/pkg/event/event_marshal_test.go
index 26be8eb..5260665 100644
--- a/pkg/event/event_marshal_test.go
+++ b/pkg/event/event_marshal_test.go
@@ -24,11 +24,11 @@ import (
 func TestMarshal(t *testing.T) {
 	now := types.Timestamp{Time: time.Now().UTC()}
 	sourceUrl, _ := url.Parse("http://example.com/source")
-	source := &types.URLRef{URL: *sourceUrl}
+	source := &types.URIRef{URL: *sourceUrl}
 	sourceV1 := &types.URIRef{URL: *sourceUrl}
 
 	schemaUrl, _ := url.Parse("http://example.com/schema")
-	schema := &types.URLRef{URL: *schemaUrl}
+	schema := &types.URIRef{URL: *schemaUrl}
 	schemaV1 := &types.URI{URL: *schemaUrl}
 
 	testCases := map[string]struct {
@@ -304,11 +304,11 @@ func TestMarshal(t *testing.T) {
 func TestUnmarshal(t *testing.T) {
 	now := types.Timestamp{Time: time.Now().UTC()}
 	sourceUrl, _ := url.Parse("http://example.com/source")
-	source := &types.URLRef{URL: *sourceUrl}
+	source := &types.URIRef{URL: *sourceUrl}
 	sourceV1 := &types.URIRef{URL: *sourceUrl}
 
 	schemaUrl, _ := url.Parse("http://example.com/schema")
-	schema := &types.URLRef{URL: *schemaUrl}
+	schema := &types.URIRef{URL: *schemaUrl}
 	schemaV1 := &types.URI{URL: *schemaUrl}
 
 	testCases := map[string]struct {
diff --git a/pkg/event/event_test.go b/pkg/event/event_test.go
index f3307ed..d27db4a 100644
--- a/pkg/event/event_test.go
+++ b/pkg/event/event_test.go
@@ -487,7 +487,7 @@ func strptr(s string) *string {
 
 func MinEventContextV03() *event.EventContextV03 {
 	sourceUrl, _ := url.Parse("http://example.com/source")
-	source := &types.URLRef{URL: *sourceUrl}
+	source := &types.URIRef{URL: *sourceUrl}
 
 	return event.EventContextV03{
 		Type:   "com.example.simple",
@@ -509,10 +509,10 @@ func MinEventContextV1() *event.EventContextV1 {
 
 func FullEventContextV03(now types.Timestamp) *event.EventContextV03 {
 	sourceUrl, _ := url.Parse("http://example.com/source")
-	source := &types.URLRef{URL: *sourceUrl}
+	source := &types.URIRef{URL: *sourceUrl}
 
 	schemaUrl, _ := url.Parse("http://example.com/schema")
-	schema := &types.URLRef{URL: *schemaUrl}
+	schema := &types.URIRef{URL: *schemaUrl}
 
 	eventContextV03 := event.EventContextV03{
 		ID:                  "ABC-123",
diff --git a/pkg/event/eventcontext_v03_test.go b/pkg/event/eventcontext_v03_test.go
index 553285f..13c29ee 100644
--- a/pkg/event/eventcontext_v03_test.go
+++ b/pkg/event/eventcontext_v03_test.go
@@ -16,12 +16,12 @@ func TestValidateV03(t *testing.T) {
 	now := types.Timestamp{Time: time.Now()}
 
 	sourceUrl, _ := url.Parse("http://example.com/source")
-	source := &types.URLRef{URL: *sourceUrl}
+	source := &types.URIRef{URL: *sourceUrl}
 
 	subject := "a subject"
 
 	schemaUrl, _ := url.Parse("http://example.com/schema")
-	schema := &types.URLRef{URL: *schemaUrl}
+	schema := &types.URIRef{URL: *schemaUrl}
 
 	extensions := make(map[string]interface{})
 	extensions["test"] = "extended"
@@ -101,7 +101,7 @@ func TestValidateV03(t *testing.T) {
 				SpecVersion: event.CloudEventsVersionV03,
 				ID:          "ABC-123",
 				Type:        "com.example.simple",
-				SchemaURL:   &types.URLRef{},
+				SchemaURL:   &types.URIRef{},
 				Source:      *source,
 			},
 			want: []string{"schemaurl:"},
@@ -151,7 +151,7 @@ func TestValidateV03(t *testing.T) {
 			ctx: event.EventContextV03{
 				SpecVersion:     "",
 				ID:              "",
-				SchemaURL:       &types.URLRef{},
+				SchemaURL:       &types.URIRef{},
 				DataContentType: strptr(""),
 				Extensions:      make(map[string]interface{}),
 			},
diff --git a/pkg/extensions/distributed_tracing_extension_test.go b/pkg/extensions/distributed_tracing_extension_test.go
index 8c3d5ac..c548fbe 100644
--- a/pkg/extensions/distributed_tracing_extension_test.go
+++ b/pkg/extensions/distributed_tracing_extension_test.go
@@ -22,11 +22,11 @@ type Data struct {
 var now = types.Timestamp{Time: time.Now().UTC()}
 
 var sourceUrl, _ = url.Parse("http://example.com/source")
-var source = &types.URLRef{URL: *sourceUrl}
+var source = &types.URIRef{URL: *sourceUrl}
 var sourceUri = &types.URIRef{URL: *sourceUrl}
 
 var schemaUrl, _ = url.Parse("http://example.com/schema")
-var schema = &types.URLRef{URL: *schemaUrl}
+var schema = &types.URIRef{URL: *schemaUrl}
 var schemaUri = &types.URI{URL: *schemaUrl}
 
 type values struct {
diff --git a/pkg/transport/http/message_write_response_test.go b/pkg/transport/http/message_write_responsewriter_test.go
similarity index 70%
rename from pkg/transport/http/message_write_response_test.go
rename to pkg/transport/http/message_write_responsewriter_test.go
index ac2e24e..6c290eb 100644
--- a/pkg/transport/http/message_write_response_test.go
+++ b/pkg/transport/http/message_write_responsewriter_test.go
@@ -1,12 +1,12 @@
 package http
 
 import (
+	"bytes"
 	"context"
-	"net/http"
+	"io/ioutil"
+	"net/http/httptest"
 	"testing"
 
-	test2 "github.com/cloudevents/sdk-go/pkg/binding/test"
-
 	"github.com/stretchr/testify/require"
 
 	"github.com/cloudevents/sdk-go/pkg/binding"
@@ -14,7 +14,7 @@ import (
 	"github.com/cloudevents/sdk-go/pkg/event"
 )
 
-func TestEncodeHttpResponse(t *testing.T) {
+func TestWriteHttpResponseWriter(t *testing.T) {
 	tests := []struct {
 		name             string
 		context          context.Context
@@ -47,24 +47,30 @@ func TestEncodeHttpResponse(t *testing.T) {
 		},
 	}
 	for _, tt := range tests {
-		test2.EachEvent(t, test.Events(), func(t *testing.T, eventIn event.Event) {
+		test.EachEvent(t, test.Events(), func(t *testing.T, eventIn event.Event) {
 			t.Run(tt.name, func(t *testing.T) {
-				res := &http.Response{
-					Header: make(http.Header),
-				}
+				res := httptest.NewRecorder()
 
-				eventIn = test2.ExToStr(t, eventIn)
+				eventIn = test.ExToStr(t, eventIn)
 				messageIn := tt.messageFactory(eventIn)
 
-				err := WriteResponse(tt.context, messageIn, res, nil)
+				shouldHaveContentLength := eventIn.Data != nil || messageIn.ReadEncoding() == binding.EncodingStructured
+
+				err := WriteResponseWriter(tt.context, messageIn, 200, res, nil)
 				require.NoError(t, err)
 
+				require.Equal(t, 200, res.Code)
+				if shouldHaveContentLength {
+					require.NotZero(t, res.Header().Get("content-length"))
+				}
+
 				//Little hack to go back to Message
-				messageOut := NewMessageFromHttpResponse(res)
+				messageOut := NewMessage(res.Header(), ioutil.NopCloser(bytes.NewReader(res.Body.Bytes())))
 				require.Equal(t, tt.expectedEncoding, messageOut.ReadEncoding())
 
 				eventOut, err := binding.ToEvent(context.TODO(), messageOut, nil)
-				test2.AssertEventEquals(t, eventIn, *eventOut)
+				require.NoError(t, err)
+				test.AssertEventEquals(t, eventIn, *eventOut)
 			})
 		})
 	}
diff --git a/pkg/types/urlref_test.go b/pkg/types/urlref_test.go
deleted file mode 100644
index 280ceb6..0000000
--- a/pkg/types/urlref_test.go
+++ /dev/null
@@ -1,271 +0,0 @@
-package types_test
-
-import (
-	"encoding/xml"
-	"net/url"
-	"testing"
-
-	"github.com/cloudevents/sdk-go/pkg/types"
-	"github.com/google/go-cmp/cmp"
-)
-
-func TestParseURLRef(t *testing.T) {
-	testCases := map[string]struct {
-		t    string
-		want *types.URLRef
-	}{
-		"empty": {
-			want: nil,
-		},
-		"empty string": {
-			t:    "",
-			want: nil,
-		},
-		"invalid format": {
-			t:    "💩://error",
-			want: nil,
-		},
-		"relative": {
-			t: "/path/to/something",
-			want: func() *types.URLRef {
-				u, _ := url.Parse("/path/to/something")
-				return &types.URLRef{URL: *u}
-			}(),
-		},
-		"url": {
-			t: "http://path/to/something",
-			want: func() *types.URLRef {
-				u, _ := url.Parse("http://path/to/something")
-				return &types.URLRef{URL: *u}
-			}(),
-		},
-	}
-	for n, tc := range testCases {
-		tc := tc // Don't use range variable in func literal.
-		t.Run(n, func(t *testing.T) {
-
-			got := types.ParseURLRef(tc.t)
-
-			if diff := cmp.Diff(tc.want, got); diff != "" {
-				t.Errorf("unexpected object (-want, +got) = %v", diff)
-			}
-		})
-	}
-}
-
-func TestJsonMarshalURLRef(t *testing.T) {
-	testCases := map[string]struct {
-		t    string
-		want []byte
-	}{
-		"empty": {},
-		"empty string": {
-			t: "",
-		},
-		"invalid url": {
-			t:    "not a url",
-			want: []byte(`"not%20a%20url"`),
-		},
-		"relative format": {
-			t:    "/path/to/something",
-			want: []byte(`"/path/to/something"`),
-		},
-	}
-	for n, tc := range testCases {
-		tc := tc // Don't use range variable in func literal.
-		t.Run(n, func(t *testing.T) {
-
-			var got []byte
-			tt := types.ParseURLRef(tc.t)
-			if tt != nil {
-				got, _ = tt.MarshalJSON()
-			}
-
-			if diff := cmp.Diff(tc.want, got); diff != "" {
-				t.Logf("got: %s", string(got))
-				t.Errorf("unexpected object (-want, +got) = %v", diff)
-			}
-		})
-	}
-}
-
-func TestXMLMarshalURLRef(t *testing.T) {
-	testCases := map[string]struct {
-		t    string
-		want []byte
-	}{
-		"empty": {},
-		"empty string": {
-			t: "",
-		},
-		"invalid url": {
-			t:    "not a url",
-			want: []byte(`<URLRef>not%20a%20url</URLRef>`),
-		},
-		"relative format": {
-			t:    "/path/to/something",
-			want: []byte(`<URLRef>/path/to/something</URLRef>`),
-		},
-	}
-	for n, tc := range testCases {
-		tc := tc // Don't use range variable in func literal.
-		t.Run(n, func(t *testing.T) {
-
-			var got []byte
-			tt := types.ParseURLRef(tc.t)
-			if tt != nil {
-				got, _ = xml.Marshal(tt)
-			}
-
-			if diff := cmp.Diff(tc.want, got); diff != "" {
-				t.Logf("got: %s", string(got))
-				t.Errorf("unexpected object (-want, +got) = %v", diff)
-			}
-		})
-	}
-}
-
-func TestJsonUnmarshalURLRef(t *testing.T) {
-	testCases := map[string]struct {
-		b       []byte
-		want    *types.URLRef
-		wantErr string
-	}{
-		"empty": {
-			wantErr: "unexpected end of JSON input",
-		},
-		"invalid format": {
-			b:       []byte("%"),
-			wantErr: "invalid character '%' looking for beginning of value",
-		},
-		"relative": {
-			b: []byte(`"/path/to/something"`),
-			want: func() *types.URLRef {
-				u, _ := url.Parse("/path/to/something")
-				return &types.URLRef{URL: *u}
-			}(),
-		},
-		"url": {
-			b: []byte(`"http://path/to/something"`),
-			want: func() *types.URLRef {
-				u, _ := url.Parse("http://path/to/something")
-				return &types.URLRef{URL: *u}
-			}(),
-		},
-	}
-	for n, tc := range testCases {
-		tc := tc // Don't use range variable in func literal.
-		t.Run(n, func(t *testing.T) {
-
-			got := &types.URLRef{}
-			err := got.UnmarshalJSON(tc.b)
-
-			if tc.wantErr != "" || err != nil {
-				var gotErr string
-				if err != nil {
-					gotErr = err.Error()
-				}
-				if diff := cmp.Diff(tc.wantErr, gotErr); diff != "" {
-					t.Errorf("unexpected error (-want, +got) = %v", diff)
-				}
-				return
-			}
-
-			if diff := cmp.Diff(tc.want, got); diff != "" {
-				t.Errorf("unexpected object (-want, +got) = %v", diff)
-			}
-		})
-	}
-}
-
-func TestXMLUnmarshalURLRef(t *testing.T) {
-	testCases := map[string]struct {
-		b       []byte
-		want    *types.URLRef
-		wantErr string
-	}{
-		"empty": {
-			wantErr: "EOF",
-		},
-		"invalid format": {
-			b:    []byte(`<URLRef>%</URLRef>`),
-			want: &types.URLRef{},
-		},
-		"bad xml": {
-			b:       []byte(`<URLRef><bad>%<bad></URLRef>`),
-			wantErr: "XML syntax error on line 1: element <bad> closed by </URLRef>",
-		},
-		"relative": {
-			b: []byte(`<URLRef>/path/to/something</URLRef>`),
-			want: func() *types.URLRef {
-				u, _ := url.Parse("/path/to/something")
-				return &types.URLRef{URL: *u}
-			}(),
-		},
-		"url": {
-			b: []byte(`<URLRef>http://path/to/something</URLRef>`),
-			want: func() *types.URLRef {
-				u, _ := url.Parse("http://path/to/something")
-				return &types.URLRef{URL: *u}
-			}(),
-		},
-	}
-	for n, tc := range testCases {
-		tc := tc // Don't use range variable in func literal.
-		t.Run(n, func(t *testing.T) {
-
-			got := &types.URLRef{}
-
-			err := xml.Unmarshal(tc.b, got)
-
-			if tc.wantErr != "" || err != nil {
-				var gotErr string
-				if err != nil {
-					gotErr = err.Error()
-				}
-				if diff := cmp.Diff(tc.wantErr, gotErr); diff != "" {
-					t.Errorf("unexpected error (-want, +got) = %v", diff)
-				}
-				return
-			}
-
-			if diff := cmp.Diff(tc.want, got); diff != "" {
-				t.Errorf("unexpected object (-want, +got) = %v", diff)
-			}
-		})
-	}
-}
-
-func TestURLRefString(t *testing.T) {
-	testCases := map[string]struct {
-		t    string
-		want string
-	}{
-		"empty": {
-			want: "",
-		},
-		"relative": {
-			t:    "/path/to/something",
-			want: "/path/to/something",
-		},
-		"url": {
-			t:    "http://path/to/something",
-			want: "http://path/to/something",
-		},
-	}
-	for n, tc := range testCases {
-		tc := tc // Don't use range variable in func literal.
-		t.Run(n, func(t *testing.T) {
-
-			tt := types.ParseURLRef(tc.t)
-			got := tt.String()
-
-			if diff := cmp.Diff(tc.want, got); diff != "" {
-				t.Logf("got: %s", got)
-				t.Errorf("unexpected string (-want, +got) = %v", diff)
-			}
-		})
-	}
-}
-
-// TODO: Test xml:  MarshalXML(e *xml.Encoder, start xml.StartElement) error {
diff --git a/pkg/types/value_test.go b/pkg/types/value_test.go
index 027f866..9aa0543 100644
--- a/pkg/types/value_test.go
+++ b/pkg/types/value_test.go
@@ -201,8 +201,6 @@ func TestURL(t *testing.T) {
 	x := valueTester{t, types.ToURL}
 	x.ok(testURL, types.URI{*testURL}, testURLstr)
 	x.ok(*testURL, types.URI{*testURL}, testURLstr)
-	x.okWithDifferentFromString(types.URLRef{URL: *testURL}, types.URIRef{*testURL}, testURLstr, types.URI{*testURL})
-	x.okWithDifferentFromString(&types.URLRef{URL: *testURL}, types.URIRef{*testURL}, testURLstr, types.URI{*testURL})
 	x.okWithDifferentFromString(types.URIRef{URL: *testURL}, types.URIRef{*testURL}, testURLstr, types.URI{*testURL})
 	x.okWithDifferentFromString(&types.URIRef{URL: *testURL}, types.URIRef{*testURL}, testURLstr, types.URI{*testURL})
 	x.ok(types.URI{URL: *testURL}, types.URI{*testURL}, testURLstr)
diff --git a/test/integration/http/loopback_setters_test.go b/test/integration/http/loopback_setters_test.go
index 6ad27b9..3bb2399 100644
--- a/test/integration/http/loopback_setters_test.go
+++ b/test/integration/http/loopback_setters_test.go
@@ -59,7 +59,7 @@ func TestClientLoopback_setters_binary_json(t *testing.T) {
 						ID:              "321-CBA",
 						Type:            "unit.test.client.response",
 						Time:            &cloudevents.Timestamp{Time: now},
-						Source:          *cloudevents.ParseURLRef("/unit/test/client"),
+						Source:          *cloudevents.ParseURIRef("/unit/test/client"),
 						DataContentType: cloudevents.StringOfApplicationJSON(),
 					}.AsV03(),
 					Data: map[string]string{"unittest": "response"},
@@ -189,7 +189,7 @@ func TestClientLoopback_setters_binary_json_noBody(t *testing.T) {
 						ID:              "321-CBA",
 						Type:            "unit.test.client.response",
 						Time:            &cloudevents.Timestamp{Time: now},
-						Source:          *cloudevents.ParseURLRef("/unit/test/client"),
+						Source:          *cloudevents.ParseURIRef("/unit/test/client"),
 						DataContentType: cloudevents.StringOfApplicationJSON(),
 					}.AsV03(),
 					Data: map[string]string{},
@@ -321,7 +321,7 @@ func TestClientLoopback_setters_structured_json(t *testing.T) {
 						ID:              "321-CBA",
 						Type:            "unit.test.client.response",
 						Time:            &cloudevents.Timestamp{Time: now},
-						Source:          *cloudevents.ParseURLRef("/unit/test/client"),
+						Source:          *cloudevents.ParseURIRef("/unit/test/client"),
 						DataContentType: cloudevents.StringOfApplicationJSON(),
 					}.AsV03(),
 					Data: map[string]string{"unittest": "response"},
@@ -432,7 +432,7 @@ func TestClientLoopback_setters_structured_json_base64(t *testing.T) {
 						ID:                  "321-CBA",
 						Type:                "unit.test.client.response",
 						Time:                &cloudevents.Timestamp{Time: now},
-						Source:              *cloudevents.ParseURLRef("/unit/test/client"),
+						Source:              *cloudevents.ParseURIRef("/unit/test/client"),
 						DataContentType:     cloudevents.StringOfApplicationJSON(),
 						DataContentEncoding: cloudevents.StringOfBase64(),
 					}.AsV03(),
diff --git a/test/integration/http/loopback_v03_test.go b/test/integration/http/loopback_v03_test.go
index c532eb2..2675dc0 100644
--- a/test/integration/http/loopback_v03_test.go
+++ b/test/integration/http/loopback_v03_test.go
@@ -18,7 +18,7 @@ func TestClientLoopback_binary_v03tov03(t *testing.T) {
 				Context: cloudevents.EventContextV03{
 					ID:              "ABC-123",
 					Type:            "unit.test.client.sent",
-					Source:          *cloudevents.ParseURLRef("/unit/test/client"),
+					Source:          *cloudevents.ParseURIRef("/unit/test/client"),
 					Subject:         strptr("resource"),
 					DataContentType: cloudevents.StringOfApplicationJSON(),
 				}.AsV03(),
@@ -28,7 +28,7 @@ func TestClientLoopback_binary_v03tov03(t *testing.T) {
 				Context: cloudevents.EventContextV03{
 					ID:              "321-CBA",
 					Type:            "unit.test.client.response",
-					Source:          *cloudevents.ParseURLRef("/unit/test/client"),
+					Source:          *cloudevents.ParseURIRef("/unit/test/client"),
 					DataContentType: cloudevents.StringOfApplicationJSON(),
 				}.AsV03(),
 				Data: map[string]string{"unittest": "response"},
@@ -38,7 +38,7 @@ func TestClientLoopback_binary_v03tov03(t *testing.T) {
 					ID:              "321-CBA",
 					Type:            "unit.test.client.response",
 					Time:            &cloudevents.Timestamp{Time: now},
-					Source:          *cloudevents.ParseURLRef("/unit/test/client"),
+					Source:          *cloudevents.ParseURIRef("/unit/test/client"),
 					DataContentType: cloudevents.StringOfApplicationJSON(),
 				}.AsV03(),
 				Data: map[string]string{"unittest": "response"},
@@ -93,7 +93,7 @@ func TestClientLoopback_binary_base64_v03tov03(t *testing.T) {
 				Context: cloudevents.EventContextV03{
 					ID:                  "ABC-123",
 					Type:                "unit.test.client.sent",
-					Source:              *cloudevents.ParseURLRef("/unit/test/client"),
+					Source:              *cloudevents.ParseURIRef("/unit/test/client"),
 					Subject:             strptr("resource"),
 					DataContentEncoding: cloudevents.StringOfBase64(),
 					DataContentType:     cloudevents.StringOfApplicationJSON(),
@@ -104,7 +104,7 @@ func TestClientLoopback_binary_base64_v03tov03(t *testing.T) {
 				Context: cloudevents.EventContextV03{
 					ID:                  "321-CBA",
 					Type:                "unit.test.client.response",
-					Source:              *cloudevents.ParseURLRef("/unit/test/client"),
+					Source:              *cloudevents.ParseURIRef("/unit/test/client"),
 					DataContentEncoding: cloudevents.StringOfBase64(),
 					DataContentType:     cloudevents.StringOfApplicationJSON(),
 				}.AsV03(),
@@ -115,7 +115,7 @@ func TestClientLoopback_binary_base64_v03tov03(t *testing.T) {
 					ID:                  "321-CBA",
 					Type:                "unit.test.client.response",
 					Time:                &cloudevents.Timestamp{Time: now},
-					Source:              *cloudevents.ParseURLRef("/unit/test/client"),
+					Source:              *cloudevents.ParseURIRef("/unit/test/client"),
 					DataContentType:     cloudevents.StringOfApplicationJSON(),
 					DataContentEncoding: cloudevents.StringOfBase64(),
 				}.AsV03(),
@@ -172,7 +172,7 @@ func TestClientLoopback_structured_base64_v03tov03(t *testing.T) {
 				Context: cloudevents.EventContextV03{
 					ID:                  "ABC-123",
 					Type:                "unit.test.client.sent",
-					Source:              *cloudevents.ParseURLRef("/unit/test/client"),
+					Source:              *cloudevents.ParseURIRef("/unit/test/client"),
 					DataContentEncoding: cloudevents.StringOfBase64(),
 					DataContentType:     cloudevents.StringOfApplicationJSON(),
 				}.AsV03(),
@@ -182,7 +182,7 @@ func TestClientLoopback_structured_base64_v03tov03(t *testing.T) {
 				Context: cloudevents.EventContextV03{
 					ID:                  "321-CBA",
 					Type:                "unit.test.client.response",
-					Source:              *cloudevents.ParseURLRef("/unit/test/client"),
+					Source:              *cloudevents.ParseURIRef("/unit/test/client"),
 					DataContentEncoding: cloudevents.StringOfBase64(),
 					DataContentType:     cloudevents.StringOfApplicationJSON(),
 				}.AsV03(),
@@ -193,7 +193,7 @@ func TestClientLoopback_structured_base64_v03tov03(t *testing.T) {
 					ID:                  "321-CBA",
 					Type:                "unit.test.client.response",
 					Time:                &cloudevents.Timestamp{Time: now},
-					Source:              *cloudevents.ParseURLRef("/unit/test/client"),
+					Source:              *cloudevents.ParseURIRef("/unit/test/client"),
 					DataContentType:     cloudevents.StringOfApplicationJSON(),
 					DataContentEncoding: cloudevents.StringOfBase64(),
 				}.AsV03(),
diff --git a/test/integration/http/loopback_v1_test.go b/test/integration/http/loopback_v1_test.go
index f886b01..0fbf7b2 100644
--- a/test/integration/http/loopback_v1_test.go
+++ b/test/integration/http/loopback_v1_test.go
@@ -29,7 +29,7 @@ func TestClientLoopback_binary_v1tov03(t *testing.T) {
 				Context: cloudevents.EventContextV03{
 					ID:              "321-CBA",
 					Type:            "unit.test.client.response",
-					Source:          *cloudevents.ParseURLRef("/unit/test/client"),
+					Source:          *cloudevents.ParseURIRef("/unit/test/client"),
 					DataContentType: cloudevents.StringOfApplicationJSON(),
 				}.AsV03(),
 				Data: map[string]string{"unittest": "response"},
@@ -39,7 +39,7 @@ func TestClientLoopback_binary_v1tov03(t *testing.T) {
 					ID:              "321-CBA",
 					Type:            "unit.test.client.response",
 					Time:            &cloudevents.Timestamp{Time: now},
-					Source:          *cloudevents.ParseURLRef("/unit/test/client"),
+					Source:          *cloudevents.ParseURIRef("/unit/test/client"),
 					DataContentType: cloudevents.StringOfApplicationJSON(),
 				}.AsV03(),
 				Data: map[string]string{"unittest": "response"},
@@ -174,7 +174,7 @@ func TestClientLoopback_structured_base64_v03tov1(t *testing.T) {
 				Context: cloudevents.EventContextV03{
 					ID:                  "ABC-123",
 					Type:                "unit.test.client.sent",
-					Source:              *cloudevents.ParseURLRef("/unit/test/client"),
+					Source:              *cloudevents.ParseURIRef("/unit/test/client"),
 					DataContentEncoding: cloudevents.StringOfBase64(),
 					DataContentType:     cloudevents.StringOfApplicationJSON(),
 				}.AsV03(),