Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbbbd3c2

Browse files
committed
pr comments
1 parente291e8c commitbbbd3c2

File tree

5 files changed

+93
-62
lines changed

5 files changed

+93
-62
lines changed

‎coderd/tailnet.go‎

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bufio"
55
"context"
66
"crypto/tls"
7+
"errors"
78
"fmt"
89
"net"
910
"net/http"
@@ -362,23 +363,27 @@ func (s *ServerTailnet) ReverseProxy(targetURL, dashboardURL *url.URL, agentID u
362363
switchTarget=""
363364
)
364365

365-
ifstrings.Contains(theErr.Error(),"tls:") {
366+
vartlsError tls.RecordHeaderError
367+
if (errors.As(theErr,&tlsError)&&tlsError.Msg=="first record does not look like a TLS handshake")||
368+
errors.Is(theErr,http.ErrSchemeMismatch) {
366369
// If the error is due to an HTTP/HTTPS mismatch, we can provide a
367370
// more helpful error message with redirect buttons.
368371
switchURL:= url.URL{
369372
Scheme:dashboardURL.Scheme,
370373
}
371-
ifapp.IsPort() {
372-
ifapp.PortProtocol()=="https" {
373-
app.ChangePortProtocol("http")
374-
}else {
375-
app.ChangePortProtocol("https")
374+
_,protocol,isPort:=app.PortInfo()
375+
ifisPort {
376+
ifprotocol=="https" {
377+
app=app.ChangePortProtocol("http")
378+
}
379+
ifprotocol=="http" {
380+
app=app.ChangePortProtocol("https")
376381
}
377382

378383
switchURL.Host=fmt.Sprintf("%s%s",app.String(),strings.TrimPrefix(wildcardHostname,"*"))
379384
switchLink=switchURL.String()
380-
switchTarget=app.PortProtocol()
381-
additional+=fmt.Sprintf("This error seems to be due to an app protocol mismatch, try switching to %s.",strings.ToUpper(app.PortProtocol()))
385+
switchTarget=protocol
386+
additional+=fmt.Sprintf("This error seems to be due to an app protocol mismatch, try switching to %s.",strings.ToUpper(protocol))
382387
}
383388
}
384389

@@ -388,9 +393,9 @@ func (s *ServerTailnet) ReverseProxy(targetURL, dashboardURL *url.URL, agentID u
388393
Description:desc,
389394
RetryEnabled:true,
390395
DashboardURL:dashboardURL.String(),
391-
SwitchProtocolLink:switchLink,
392-
SwitchProtocolTarget:strings.ToUpper(switchTarget),
393396
AdditionalInfo:additional,
397+
AdditionalButtonLink:switchLink,
398+
AdditionalButtonText:fmt.Sprintf("Switch to %s",strings.ToUpper(switchTarget)),
394399
})
395400
}
396401
proxy.Director=s.director(agentID,proxy.Director)

‎coderd/workspaceapps/appurl/appurl.go‎

Lines changed: 68 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -84,62 +84,87 @@ func (a ApplicationURL) Path() string {
8484
returnfmt.Sprintf("/@%s/%s.%s/apps/%s",a.Username,a.WorkspaceName,a.AgentName,a.AppSlugOrPort)
8585
}
8686

87-
func (aApplicationURL)IsPort()bool {
88-
// check if https port
89-
ifstrings.HasSuffix(a.AppSlugOrPort,"s") {
90-
trimmed:=strings.TrimSuffix(a.AppSlugOrPort,"s")
91-
_,err:=strconv.ParseInt(trimmed,10,64)
92-
//nolint:gosimple
93-
iferr!=nil {
94-
returnfalse
95-
}
96-
97-
returntrue
98-
}
99-
100-
// check if port at all
101-
_,err:=strconv.ParseInt(a.AppSlugOrPort,10,64)
102-
//nolint:gosimple
103-
iferr!=nil {
104-
returnfalse
105-
}
106-
107-
returntrue
108-
}
87+
// func (a ApplicationURL) IsPort() bool {
88+
// // check if https port
89+
// if strings.HasSuffix(a.AppSlugOrPort, "s") {
90+
// trimmed := strings.TrimSuffix(a.AppSlugOrPort, "s")
91+
// _, err := strconv.ParseInt(trimmed, 10, 64)
92+
// //nolint:gosimple
93+
// if err != nil {
94+
// return false
95+
// }
96+
97+
// return true
98+
// }
99+
100+
// // check if port at all
101+
// _, err := strconv.ParseInt(a.AppSlugOrPort, 10, 64)
102+
// //nolint:gosimple
103+
// if err != nil {
104+
// return false
105+
// }
106+
107+
// return true
108+
// }
109+
110+
// func (a ApplicationURL) PortProtocol() string {
111+
// if strings.HasSuffix(a.AppSlugOrPort, "s") {
112+
// trimmed := strings.TrimSuffix(a.AppSlugOrPort, "s")
113+
// _, err := strconv.ParseInt(trimmed, 10, 64)
114+
// if err == nil {
115+
// return "https"
116+
// }
117+
// }
118+
119+
// return "http"
120+
// }
121+
122+
func (aApplicationURL)PortInfo() (uint,string,bool) {
123+
var (
124+
portuint64
125+
protocolstring
126+
isPortbool
127+
errerror
128+
)
109129

110-
func (aApplicationURL)PortProtocol()string {
111130
ifstrings.HasSuffix(a.AppSlugOrPort,"s") {
112131
trimmed:=strings.TrimSuffix(a.AppSlugOrPort,"s")
113-
_,err:=strconv.ParseInt(trimmed,10,64)
132+
port,err=strconv.ParseUint(trimmed,10,16)
133+
iferr==nil {
134+
protocol="https"
135+
isPort=true
136+
}
137+
}else {
138+
port,err=strconv.ParseUint(a.AppSlugOrPort,10,16)
114139
iferr==nil {
115-
return"https"
140+
protocol="http"
141+
isPort=true
116142
}
117143
}
118144

119-
return"http"
145+
returnuint(port),protocol,isPort
120146
}
121147

122-
func (a*ApplicationURL)ChangePortProtocol(targetstring) {
123-
iftarget=="http" {
124-
ifa.PortProtocol()=="http" {
125-
return
126-
}
127-
trimmed:=strings.TrimSuffix(a.AppSlugOrPort,"s")
128-
_,err:=strconv.ParseInt(trimmed,10,64)
129-
iferr==nil {
130-
a.AppSlugOrPort=trimmed
131-
}
148+
func (a*ApplicationURL)ChangePortProtocol(targetstring)ApplicationURL {
149+
newAppURL:=*a
150+
port,protocol,isPort:=a.PortInfo()
151+
if!isPort {
152+
returnnewAppURL
153+
}
154+
155+
iftarget==protocol {
156+
returnnewAppURL
132157
}
133158

134159
iftarget=="https" {
135-
ifa.PortProtocol()=="https" {
136-
return
137-
}
138-
_,err:=strconv.ParseInt(a.AppSlugOrPort,10,64)
139-
iferr==nil {
140-
a.AppSlugOrPort=fmt.Sprintf("%s%s",a.AppSlugOrPort,"s")
141-
}
160+
newAppURL.AppSlugOrPort=fmt.Sprintf("%ds",port)
142161
}
162+
163+
iftarget=="http" {
164+
newAppURL.AppSlugOrPort=fmt.Sprintf("%d",port)
165+
}
166+
167+
returnnewAppURL
143168
}
144169

145170
// ParseSubdomainAppURL parses an ApplicationURL from the given subdomain. If

‎coderd/workspaceapps/proxy.go‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,8 +545,9 @@ func (s *Server) proxyWorkspaceApp(rw http.ResponseWriter, r *http.Request, appT
545545

546546
r.URL.Path=path
547547
appURL.RawQuery=""
548-
ifapp.IsPort() {
549-
appURL.Scheme=app.PortProtocol()
548+
_,protocol,isPort:=app.PortInfo()
549+
ifisPort {
550+
appURL.Scheme=protocol
550551
}
551552

552553
proxy:=s.AgentProvider.ReverseProxy(appURL,s.DashboardURL,appToken.AgentID,app,s.Hostname)

‎site/site.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,9 +792,9 @@ type ErrorPageData struct {
792792
RetryEnabledbool
793793
DashboardURLstring
794794
Warnings []string
795-
SwitchProtocolLinkstring
796-
SwitchProtocolTargetstring
797795
AdditionalInfostring
796+
AdditionalButtonLinkstring
797+
AdditionalButtonTextstring
798798

799799
RenderDescriptionMarkdownbool
800800
}

‎site/static/error.html‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,12 +198,12 @@ <h3>Warnings</h3>
198198
</div>
199199
{{ end }}
200200
<divclass="button-group">
201-
{{- if .Error.RetryEnabled }}
202-
<buttononclick="window.location.reload()">Retry</button>
203-
{{ end }} {{- if .Error.SwitchProtocolLink }}
204-
<ahref="{{ .Error.SwitchProtocolLink }}"
205-
>Switch to {{ .Error.SwitchProtocolTarget }}</a
201+
{{- if and .Error.AdditionalButtonText .Error.AdditionButtonLink }}
202+
<ahref="{{ .Error.AdditionButtonLink }}"
203+
>Switch to {{ .Error.AdditionalButtonText }}</a
206204
>
205+
{{ end }} {{- if .Error.RetryEnabled }}
206+
<buttononclick="window.location.reload()">Retry</button>
207207
{{ end }}
208208
<ahref="{{ .Error.DashboardURL }}">Back to site</a>
209209
</div>

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp