Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfdc4079

Browse files
authored
1 parent897a573 commitfdc4079

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

‎accept.go‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ type AcceptOptions struct {
6363
CompressionThresholdint
6464
}
6565

66+
func (opts*AcceptOptions)cloneWithDefaults()*AcceptOptions {
67+
varoAcceptOptions
68+
ifopts!=nil {
69+
o=*opts
70+
}
71+
return&o
72+
}
73+
6674
// Accept accepts a WebSocket handshake from a client and upgrades the
6775
// the connection to a WebSocket.
6876
//
@@ -77,17 +85,13 @@ func Accept(w http.ResponseWriter, r *http.Request, opts *AcceptOptions) (*Conn,
7785
funcaccept(w http.ResponseWriter,r*http.Request,opts*AcceptOptions) (_*Conn,errerror) {
7886
defererrd.Wrap(&err,"failed to accept WebSocket connection")
7987

80-
ifopts==nil {
81-
opts=&AcceptOptions{}
82-
}
83-
opts=&*opts
84-
8588
errCode,err:=verifyClientRequest(w,r)
8689
iferr!=nil {
8790
http.Error(w,err.Error(),errCode)
8891
returnnil,err
8992
}
9093

94+
opts=opts.cloneWithDefaults()
9195
if!opts.InsecureSkipVerify {
9296
err=authenticateOrigin(r,opts.OriginPatterns)
9397
iferr!=nil {

‎dial.go‎

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,20 @@ type DialOptions struct {
4747
CompressionThresholdint
4848
}
4949

50+
func (opts*DialOptions)cloneWithDefaults()*DialOptions {
51+
varoDialOptions
52+
ifopts!=nil {
53+
o=*opts
54+
}
55+
ifo.HTTPClient==nil {
56+
o.HTTPClient=http.DefaultClient
57+
}
58+
ifo.HTTPHeader==nil {
59+
o.HTTPHeader= http.Header{}
60+
}
61+
return&o
62+
}
63+
5064
// Dial performs a WebSocket handshake on url.
5165
//
5266
// The response is the WebSocket handshake response from the server.
@@ -67,17 +81,7 @@ func Dial(ctx context.Context, u string, opts *DialOptions) (*Conn, *http.Respon
6781
funcdial(ctx context.Context,urlsstring,opts*DialOptions,rand io.Reader) (_*Conn,_*http.Response,errerror) {
6882
defererrd.Wrap(&err,"failed to WebSocket dial")
6983

70-
ifopts==nil {
71-
opts=&DialOptions{}
72-
}
73-
74-
opts=&*opts
75-
ifopts.HTTPClient==nil {
76-
opts.HTTPClient=http.DefaultClient
77-
}
78-
ifopts.HTTPHeader==nil {
79-
opts.HTTPHeader= http.Header{}
80-
}
84+
opts=opts.cloneWithDefaults()
8185

8286
secWebSocketKey,err:=secWebSocketKey(rand)
8387
iferr!=nil {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp