Skip to content

Commit 02cc4dd

Browse files
authored
Merge branch 'v3' into feat_sse_method_body
2 parents 7aa538b + 981bb3f commit 02cc4dd

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

client.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -2193,7 +2193,11 @@ func (c *Client) Clone(ctx context.Context) *Client {
21932193
cc.formData = cloneURLValues(c.formData)
21942194
cc.header = c.header.Clone()
21952195
cc.pathParams = maps.Clone(c.pathParams)
2196-
cc.credentials = c.credentials.Clone()
2196+
2197+
if c.credentials != nil {
2198+
cc.credentials = c.credentials.Clone()
2199+
}
2200+
21972201
cc.contentTypeEncoders = maps.Clone(c.contentTypeEncoders)
21982202
cc.contentTypeDecoders = maps.Clone(c.contentTypeDecoders)
21992203
cc.contentDecompressers = maps.Clone(c.contentDecompressers)

sse.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -363,14 +363,15 @@ func (es *EventSource) Get() error {
363363
if isStringEmpty(es.url) {
364364
return fmt.Errorf("resty:sse: event source URL is required")
365365
}
366+
366367
if isStringEmpty(es.method) {
367368
// It is up to the user to choose which http method to use, depending on the specific code implementation. No restrictions are imposed here.
368369
// Ensure compatibility, use GET as default http method
369370
es.method = defaultHTTPMethod
370371
}
371372

372-
if _, found := es.onEvent[defaultEventName]; !found {
373-
return fmt.Errorf("resty:sse: OnMessage function is required")
373+
if len(es.onEvent) == 0 {
374+
return fmt.Errorf("resty:sse: At least one OnMessage/AddEventListener func is required")
374375
}
375376

376377
// reset to begin

sse_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ func TestEventSourceCoverage(t *testing.T) {
341341

342342
es.SetURL("https://sse.dev/test")
343343
err2 := es.Get()
344-
assertEqual(t, "resty:sse: OnMessage function is required", err2.Error())
344+
assertEqual(t, "resty:sse: At least one OnMessage/AddEventListener func is required", err2.Error())
345345

346346
es.OnMessage(func(a any) {}, nil)
347347
es.SetURL("//res%20ty.dev")

0 commit comments

Comments
 (0)