Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow custom origin header for Websocket #702

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hamann
Copy link

@hamann hamann commented Mar 7, 2024

Summary

The issue described in #641 (comment) was caused by an hardcoded origin header at

Origin = "http://localhost/"
which got validated by the websocket server and returend 403 (bad status, from https://github.com/golang/net/blob/ab271c317248ea0f18481852f96d12d5eca05cf8/websocket/hybi.go#L440-L445)
This PR allows to customize the origin header.
Example

endpoints:
  - name: websocket
    url: "wss://example.org"
    interval: 10s
    headers:
      Origin: "http://gatus.example.org"
    conditions:
      - "[CONNECTED] == true"

Fixes #641

Checklist

  • Tested and/or added tests to validate that the changes work as intended, if applicable.
  • Updated documentation in README.md, if applicable.

client/client.go Outdated Show resolved Hide resolved
Comment on lines +228 to +233
// Automatically add Origin header for websocket endpoints if there isn't one specified
if endpoint.Type() == EndpointTypeWS {
if _, originHeaderExists := endpoint.Headers[OriginHeader]; !originHeaderExists {
endpoint.Headers[OriginHeader] = Origin
}
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I agree that adding support for passing the origin header is worth it, I think perhaps we shouldn't add it by default here but instead add a note in the docs mentioning that users may have to specify an Origin header.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

XMPP WSS Bad Status
2 participants