Open PotatoCloud opened 2 months ago
Hi, thanks for the PR. Can you clarify what you're trying to achieve?
Hi, thanks for the PR. Can you clarify what you're trying to achieve?
I copy the headers during the handshake into the Handshake
struct (since currently gobwas/ws
doesn't have a good way to get the handshake headers/raw headers)
Hi, thanks for the PR. Can you clarify what you're trying to achieve?
For example, some developers want to obtain the Authorization
field in the header for identity authentication.
I'm not 100% sure what is the point of passing request headers to handshake result. User can access exactly the same data by looking at request directly.
hs.Header.Get("Authorization")
==
r.Header.Get("Authorization")
What is the benefit of keeping headers in a handshake?
I'm not 100% sure what is the point of passing request headers to handshake result. User can access exactly the same data by looking at request directly.
hs.Header.Get("Authorization") == r.Header.Get("Authorization")
What is the benefit of keeping headers in a handshake?
but, func (u Upgrader) Upgrade(conn io.ReadWriter) (hs Handshake, err error)
can't do this.
For example, I want to build a pure websocket server, using net + gobwas/ws, in this case I can't do it like you do.
pure websocket server
Based purely on TCP connections, right?
Ok, I think I'm starting to understand your case. The only thing that looks scary to me is that we will start allocating/copying all the headers for each request, which is completely not acceptable with the current guarantees.
The only thing I see now is to hide it under a flag.
we will start allocating/copying all the headers for each request The only thing I see now is to hide it under a flag.
i got it, i will add build tags support for it later
No-no, not a build tag. Flag in upgraders.
Wait a sec, have you looked at OnHeader func(key, value []byte) error
? This is exactly what you need to access all the headers without copying them (see also example in README)
OnHeader func(key, value []byte) error
I tried it and found that OnHeader captures all the incoming connection headers. So I added the headers to the Handshake
No-no, not a build tag. Flag in upgraders.
got it.
all the incoming connection headers.
Exactly what you need, isn't it?
Exactly what you need, isn't it?
wrong, there is no way to know which connection the header was passed in from. for example, identity authentication needs to be performed on a specific connection, and this process cannot be completed using OnHeader
plz review it. i am not sure if what I did meets your requirements.
I will take a look tomorrow, thanks.
I will take a look tomorrow, thanks.
can u merge now? thanks.
I think we should add a Header field to Handshake. Some developers may need to process the Header of the corresponding connection. At present, it is difficult for gobwas to implement similar functions.