Skip to content

feat: add s suffix to use HTTPS for ports #12862

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

Merged
merged 10 commits into from
Apr 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
reverse parse order
  • Loading branch information
f0ssel committed Apr 8, 2024
commit 0ab922a12ecfe8db869de8eced1afa3fcd1635f6
17 changes: 7 additions & 10 deletions coderd/workspaceapps/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,20 +290,17 @@ func (r Request) getDatabase(ctx context.Context, db database.Store) (*databaseR
agentNameOrID = r.AgentNameOrID
appURL string
appSharingLevel database.AppSharingLevel
portUint, portUintErr = strconv.ParseUint(r.AppSlugOrPort, 10, 16)
protocol = "http"
potentialPortStr = strings.TrimSuffix(r.AppSlugOrPort, "s")
portUint, portUintErr = strconv.ParseUint(potentialPortStr, 10, 16)
)
// If we fail to parse the port, see if it's a port with a trailing "s" for
// HTTPS.
if portUintErr != nil && strings.HasSuffix(r.AppSlugOrPort, "s") {
appSlugOrPort := strings.TrimRight(r.AppSlugOrPort, "s")
portUint, portUintErr = strconv.ParseUint(appSlugOrPort, 10, 16)
if portUintErr == nil {
if portUintErr == nil {
// If we fail to parse the port, see if it's a port with a trailing "s" for
// HTTPS.
protocol := "http"
if strings.HasSuffix(r.AppSlugOrPort, "s") {
protocol = "https"
}
}

if portUintErr == nil {
if r.AccessMethod != AccessMethodSubdomain {
// TODO(@deansheather): this should return a 400 instead of a 500.
return nil, xerrors.New("port-based URLs are only supported for subdomain-based applications")
Expand Down