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

Code transforms for HTTP proxy and unidirectional connect #903

Merged
merged 8 commits into from
Oct 26, 2024

Conversation

FZambia
Copy link
Member

@FZambia FZambia commented Oct 20, 2024

Proposed changes

Implement code transforms for HTTP proxy and unidirectional connect. Should allow:

  • Transformation of http codes to Centrifugo protocol codes (to disconnect code or to protocol error code) in HTTP proxy, as backend can't always control the possible intermediaries in between and sometimes applications already have common middlewares which prevent request to reach business logic handler.
  • Centrifugo protocol codes to HTTP codes during connect in unidirectional HTTP-based transports. Which may be convenient for some use cases which want to inherit Centrifugo Uni SSE / Uni HTTP Stream transports but avoid disconnect code specifics upon connection attempt – now for unidirectional connect Centrifugo always returns 200 OK and then sends disconnect message with the reason in case of connection error, then closes connection.

Example of configuration (UPD. was modified taking #906 into account):

{
  "proxy_http_status_code_transforms": [
    {"status_code": 404, "to_disconnect": {"code": 4904, "reason": "not found"}},
    {"status_code": 403, "to_disconnect": {"code": 4903, "reason": "permission denied"}},
    {"status_code": 429, "to_disconnect": {"code": 4429, "reason": "too many requests"}}
  ],
  "uni_sse_connect_code_to_http_response": {
    "enabled": false,
    "transforms": [
      {"code": 4904, "to": {"status_code": 404}},
      {"code": 4903, "to": {"status_code": 403}},
      {"code": 4429, "to": {"status_code": 429}}
    ]
  },
  "uni_http_stream_connect_code_to_http_response": {
    "enabled": false,
    "transforms": [
      {"code": 4904, "to": {"status_code": 404}},
      {"code": 4903, "to": {"status_code": 403}},
      {"code": 4429, "to": {"status_code": 429}}
    ]
  }
}

GRPC proxy is out of scope for now.

This description will be updated.

@FZambia FZambia changed the title Code translates [WIP] Code translates Oct 20, 2024
@FZambia FZambia changed the title [WIP] Code translates [WIP] Code transforms Oct 21, 2024
@FZambia FZambia changed the title [WIP] Code transforms Code transforms for HTTP proxy and unidirectional connect Oct 26, 2024
@FZambia FZambia marked this pull request as ready for review October 26, 2024 05:52
@FZambia FZambia merged commit 76f1b46 into master Oct 26, 2024
4 checks passed
@FZambia FZambia deleted the code_translate branch November 3, 2024 11:09
@FZambia FZambia mentioned this pull request Nov 3, 2024
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.

1 participant