Skip to content

Add Headers with socket requests. #3615

@DaddyWarbucks

Description

@DaddyWarbucks

I realize this is pie in the sky request.

I have long wanted to be able to send header-like data in socket requests. When using REST, we have three places to transfer data with each request: body (aka data), search params (aka query), and headers. But for sockets there is no place to send "headers" with each request. HTTP headers are set at socket connection but we can't send header-like data thereafter.

I stumbled across this problem/desire again recently because my app has outgrown Feathers' authentication implementation. I am implementing sessions. Unfortunately this means removing the "timers", etc that are included with how the socket handles auth and "sessions" via the JWT. I just want to be able to pass the Authorization: Bearer 12345 with each socket request....and the auth implementation gets SOOOO much simpler.

Instead of only passing query with each request, it would be fantastic if the socket client could send params shaped like { query, headers }. So params.headers would be considered safe just like params.query. Obviously we don't want to send the entire params object because it could essentially overwrite the server side's params. But sending params.headers aligns with how REST can send headers with each request. Furthermore, we could disallow forbidden headers: https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_request_header. We could also not allow overwriting headers that already exists via the socket connection.

Furthermore, it would be great if we could create response headers like X-RateLimit-Remaining, but that is a bit more complicated.

This would give the developer a more REST-like experience and would massively simplify how sockets handle authentication.

I am willing to work on this. But looking for some feedback from @marshallswain and @daffl. Is this something we could squeeze in v6? Or is v6 too far along? Is this something you guys are even interested in at all?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions