Skip to content

NOISSUE - Add WebSocket support to HTTP Proxy#87

Merged
dborovcanin merged 28 commits intoabsmach:mainfrom
arvindh123:websocket_origins
Apr 25, 2025
Merged

NOISSUE - Add WebSocket support to HTTP Proxy#87
dborovcanin merged 28 commits intoabsmach:mainfrom
arvindh123:websocket_origins

Conversation

@arvindh123
Copy link
Copy Markdown
Contributor

Pull request title should be MF-XXX - description or NOISSUE - description where XXX is ID of issue that this PR relate to.
Please review the CONTRIBUTING.md file for detailed contributing guidelines.

What does this do?

Which issue(s) does this PR fix/relate to?

Put here Resolves #XXX to auto-close the issue that your PR fixes (if such)

List any changes that modify/break current functionality

Have you included tests for your changes?

Did you document any new/modified functionality?

Notes

Comment thread pkg/common/origincheck.go Outdated
felixgateru
felixgateru previously approved these changes Apr 16, 2025
Copy link
Copy Markdown
Contributor

@felixgateru felixgateru left a comment

Choose a reason for hiding this comment

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

LGTM

Comment thread pkg/common/bypass.go Outdated
Comment thread pkg/common/bypass.go Outdated
@arvindh123 arvindh123 assigned arvindh123 and unassigned felixgateru Apr 17, 2025
Copy link
Copy Markdown
Contributor

@felixgateru felixgateru left a comment

Choose a reason for hiding this comment

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

I am unable to start the service now:
image

@github-project-automation github-project-automation bot moved this from 🩺 Review and testing to 🚧 In Progress in Magistrala Apr 17, 2025
felixgateru

This comment was marked as duplicate.

Comment thread pkg/http/http.go Outdated
@dborovcanin
Copy link
Copy Markdown
Contributor

@arvindh123 Please resolve the comment and conflicts.

@dborovcanin dborovcanin changed the title NOISSUE: Add WebSocket support to HTTP Proxy NOISSUE - Add WebSocket support to HTTP Proxy Apr 21, 2025
@dborovcanin
Copy link
Copy Markdown
Contributor

@arvindh123 Please resolve conflicts.

Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.com>
@arvindh123 arvindh123 force-pushed the websocket_origins branch 2 times, most recently from f22b8fc to d3a1484 Compare April 22, 2025 08:40
Signed-off-by: Arvindh <arvindh91@gmail.com>
Comment thread pkg/common/origincheck.go Outdated
const errNotAllowed = "origin - %s is not allowed"

type OriginChecker interface {
CheckOrigin(r *http.Request) error
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The idea of OriginChecker and BypassMatcher was to have the same interface signature so we can use a single interface:

type Checker interface {
    Check(*http.Request) error
}

Comment thread pkg/common/helpers.go

import "strings"

func AddSuffixSlash(path string) string {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Let's avoid having generic helpers/common/util packags. Checkers are related to HTTP layer, while suffix is transport-layer path handler.

Comment thread pkg/http/http.go
Comment thread pkg/http/http.go Outdated
func (p *Proxy) handleWebSocket(w http.ResponseWriter, r *http.Request, s *session.Session) {
topic := r.URL.Path
ctx := session.NewContext(context.Background(), s)
if err := p.session.AuthConnect(ctx); err != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Create a new ws.go file with all the WS-related handling.

Comment thread pkg/http/http.go Outdated
Comment on lines +204 to +207
}
return fmt.Errorf("%s error: %w", prefix, err)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This can be confusing as to what is UP and what is DOWN. Maybe simpler "between client and mGate" and "between mGate and server"is better.

Signed-off-by: Arvindh <arvindh91@gmail.com>
Signed-off-by: Arvindh <arvindh91@gmail.com>
Comment thread pkg/http/checkers.go Outdated
Comment on lines +20 to +23
type Checkers interface {
ShouldBypass(r *http.Request) error
CheckOrigin(r *http.Request) error
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@arvindh123 Please use a single interface Checker with Check method. There is no need for this complication. Use two implementations - one for origin and the other for bypass- according to needs.

Comment thread pkg/http/http.go Outdated
switch {
case ok:
return username, password
case len(r.URL.Query()[authzQueryKey]) != 0:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use r.URL.Query().Get(authzQueryKey) instead.

Signed-off-by: Arvindh <arvindh91@gmail.com>
Copy link
Copy Markdown
Contributor

@dborovcanin dborovcanin left a comment

Choose a reason for hiding this comment

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

No need for two files with the checker suffix - a single file checker.go with both checkers implementations is fine, since implementations are relatively simple.

Comment thread pkg/http/bypasschecker.go Outdated
"regexp"
)

const errNotByPassed = "route - %s is not in bypass list"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rename to errNotBypassFmt for better self-documenting.

Comment thread pkg/http/bypasschecker.go Outdated
@@ -0,0 +1,51 @@
// Copyright (c) Abstract Machines
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use bypass instead of byPass since it's cleaner to use bypass than by pass.

Comment thread pkg/http/http.go Outdated
return username, password
case len(r.URL.Query()[authzQueryKey]) != 0:
password = r.URL.Query()[authzQueryKey][0]
case len(r.URL.Query().Get(authzQueryKey)) != 0:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

No need for len, compare to empty string.

@@ -0,0 +1,13 @@
// Copyright (c) Abstract Machines
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Rename the file to path.go.

@dborovcanin
Copy link
Copy Markdown
Contributor

@arvindh123 Please address remarks here.

Signed-off-by: Arvindh <arvindh91@gmail.com>
@dborovcanin dborovcanin merged commit d194345 into absmach:main Apr 25, 2025
1 check passed
@github-project-automation github-project-automation bot moved this from 🚧 In Progress to ✅ Done in Magistrala Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

3 participants