Skip to content

Commit 9282cdf

Browse files
committed
lint
1 parent ce89dab commit 9282cdf

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

models/repo/avatar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (repo *Repository) relAvatarLink(ctx context.Context) string {
8484
return setting.AppSubURL + "/repo-avatars/" + url.PathEscape(repo.Avatar)
8585
}
8686

87-
// AvatarLink returns a link to the repository's avatar.
87+
// AvatarLink returns the full avatar url with http host. TODO: refactor it to a relative URL, but it is still used in API response at the moment
8888
func (repo *Repository) AvatarLink(ctx context.Context) string {
8989
return httplib.MakeAbsoluteURL(ctx, repo.relAvatarLink(ctx))
9090
}

models/user/avatar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (u *User) AvatarLinkWithSize(ctx context.Context, size int) string {
8989
return avatars.GenerateEmailAvatarFastLink(ctx, u.AvatarEmail, size)
9090
}
9191

92-
// AvatarLink returns the full avatar link with http host
92+
// AvatarLink returns the full avatar url with http host. TODO: refactor it to a relative URL, but it is still used in API response at the moment
9393
func (u *User) AvatarLink(ctx context.Context) string {
9494
return httplib.MakeAbsoluteURL(ctx, u.AvatarLinkWithSize(ctx, 0))
9595
}

modules/httplib/url.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ import (
1313
"code.gitea.io/gitea/modules/util"
1414
)
1515

16-
type httpRequestContextKeyStruct struct{}
16+
type RequestContextKeyStruct struct{}
1717

18-
var HttpRequestContextKey = httpRequestContextKeyStruct{}
18+
var RequestContextKey = RequestContextKeyStruct{}
1919

2020
func urlIsRelative(s string, u *url.URL) bool {
2121
// Unfortunately browsers consider a redirect Location with preceding "//", "\\", "/\" and "\/" as meaning redirect to "http(s)://REST_OF_PATH"
@@ -32,7 +32,7 @@ func IsRelativeURL(s string) bool {
3232
return err == nil && urlIsRelative(s, u)
3333
}
3434

35-
func guessHttpRequestScheme(req *http.Request) string {
35+
func guessRequestScheme(req *http.Request) string {
3636
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Proto
3737
if s := req.Header.Get("X-Forwarded-Proto"); s != "" {
3838
return s
@@ -55,7 +55,7 @@ func guessHttpRequestScheme(req *http.Request) string {
5555
return "http"
5656
}
5757

58-
func guessHttpRequestHost(req *http.Request) string {
58+
func guessRequestHost(req *http.Request) string {
5959
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Forwarded-Host
6060
if s := req.Header.Get("X-Forwarded-Host"); s != "" {
6161
return s
@@ -68,12 +68,12 @@ func guessHttpRequestHost(req *http.Request) string {
6868

6969
// GuessCurrentAppURL tries to guess the current full URL by http headers. It always has a '/' suffix, exactly the same as setting.AppURL
7070
func GuessCurrentAppURL(ctx context.Context) string {
71-
req, ok := ctx.Value(HttpRequestContextKey).(*http.Request)
71+
req, ok := ctx.Value(RequestContextKey).(*http.Request)
7272
if !ok {
7373
return setting.AppURL
7474
}
75-
if host := guessHttpRequestHost(req); host != "" {
76-
return guessHttpRequestScheme(req) + "://" + host + setting.AppSubURL + "/"
75+
if host := guessRequestHost(req); host != "" {
76+
return guessRequestScheme(req) + "://" + host + setting.AppSubURL + "/"
7777
}
7878
return setting.AppURL
7979
}

modules/httplib/url_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,20 @@ func TestMakeAbsoluteURL(t *testing.T) {
4949
assert.Equal(t, "http://the-host/sub/foo", MakeAbsoluteURL(ctx, "/foo"))
5050
assert.Equal(t, "http://other/foo", MakeAbsoluteURL(ctx, "http://other/foo"))
5151

52-
ctx = context.WithValue(ctx, HttpRequestContextKey, &http.Request{
52+
ctx = context.WithValue(ctx, RequestContextKey, &http.Request{
5353
Host: "user-host",
5454
})
5555
assert.Equal(t, "http://user-host/sub/foo", MakeAbsoluteURL(ctx, "/foo"))
5656

57-
ctx = context.WithValue(ctx, HttpRequestContextKey, &http.Request{
57+
ctx = context.WithValue(ctx, RequestContextKey, &http.Request{
5858
Host: "user-host",
5959
Header: map[string][]string{
6060
"X-Forwarded-Host": {"forwarded-host"},
6161
},
6262
})
6363
assert.Equal(t, "http://forwarded-host/sub/foo", MakeAbsoluteURL(ctx, "/foo"))
6464

65-
ctx = context.WithValue(ctx, HttpRequestContextKey, &http.Request{
65+
ctx = context.WithValue(ctx, RequestContextKey, &http.Request{
6666
Host: "user-host",
6767
Header: map[string][]string{
6868
"X-Forwarded-Host": {"forwarded-host"},
@@ -110,7 +110,7 @@ func TestIsCurrentGiteaSiteURL(t *testing.T) {
110110
assert.False(t, IsCurrentGiteaSiteURL(ctx, "http://localhost"))
111111
assert.True(t, IsCurrentGiteaSiteURL(ctx, "http://localhost:3000?key=val"))
112112

113-
ctx = context.WithValue(ctx, HttpRequestContextKey, &http.Request{
113+
ctx = context.WithValue(ctx, RequestContextKey, &http.Request{
114114
Host: "user-host",
115115
Header: map[string][]string{
116116
"X-Forwarded-Host": {"forwarded-host"},

routers/common/middleware.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func ProtocolMiddlewares() (handlers []any) {
3636
}
3737
}()
3838
req = req.WithContext(middleware.WithContextData(req.Context()))
39-
req = req.WithContext(go_context.WithValue(req.Context(), httplib.HttpRequestContextKey, req))
39+
req = req.WithContext(go_context.WithValue(req.Context(), httplib.RequestContextKey, req))
4040
next.ServeHTTP(resp, req)
4141
})
4242
})

0 commit comments

Comments
 (0)