-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ab42c13
commit 808acb5
Showing
13 changed files
with
253 additions
and
250 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package context | ||
|
||
import ( | ||
"net/http" | ||
"testing" | ||
|
||
"code.gitea.io/gitea/modules/setting" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
type mockResponseWriter struct { | ||
header http.Header | ||
} | ||
|
||
func (m *mockResponseWriter) Header() http.Header { | ||
return m.header | ||
} | ||
|
||
func (m *mockResponseWriter) Write(bytes []byte) (int, error) { | ||
panic("implement me") | ||
} | ||
|
||
func (m *mockResponseWriter) WriteHeader(statusCode int) { | ||
panic("implement me") | ||
} | ||
|
||
func TestRemoveSessionCookieHeader(t *testing.T) { | ||
w := &mockResponseWriter{} | ||
w.header = http.Header{} | ||
w.header.Add("Set-Cookie", (&http.Cookie{Name: setting.SessionConfig.CookieName, Value: "foo"}).String()) | ||
w.header.Add("Set-Cookie", (&http.Cookie{Name: "other", Value: "bar"}).String()) | ||
assert.Len(t, w.Header().Values("Set-Cookie"), 2) | ||
removeSessionCookieHeader(w) | ||
assert.Len(t, w.Header().Values("Set-Cookie"), 1) | ||
assert.Contains(t, "other=bar", w.Header().Get("Set-Cookie")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package misc | ||
|
||
import ( | ||
"net/http" | ||
"os" | ||
"path" | ||
|
||
"code.gitea.io/gitea/modules/git" | ||
"code.gitea.io/gitea/modules/httpcache" | ||
"code.gitea.io/gitea/modules/log" | ||
"code.gitea.io/gitea/modules/setting" | ||
) | ||
|
||
func SSHInfo(rw http.ResponseWriter, req *http.Request) { | ||
if !git.SupportProcReceive { | ||
rw.WriteHeader(http.StatusNotFound) | ||
return | ||
} | ||
rw.Header().Set("content-type", "text/json;charset=UTF-8") | ||
_, err := rw.Write([]byte(`{"type":"gitea","version":1}`)) | ||
if err != nil { | ||
log.Error("fail to write result: err: %v", err) | ||
rw.WriteHeader(http.StatusInternalServerError) | ||
return | ||
} | ||
rw.WriteHeader(http.StatusOK) | ||
} | ||
|
||
func DummyOK(w http.ResponseWriter, req *http.Request) { | ||
w.WriteHeader(http.StatusOK) | ||
} | ||
|
||
func RobotsTxt(w http.ResponseWriter, req *http.Request) { | ||
filePath := path.Join(setting.CustomPath, "robots.txt") | ||
fi, err := os.Stat(filePath) | ||
if err == nil && httpcache.HandleTimeCache(req, w, fi) { | ||
return | ||
} | ||
http.ServeFile(w, req, filePath) | ||
} | ||
|
||
func StaticRedirect(target string) func(w http.ResponseWriter, req *http.Request) { | ||
return func(w http.ResponseWriter, req *http.Request) { | ||
http.Redirect(w, req, path.Join(setting.StaticURLPrefix, target), http.StatusMovedPermanently) | ||
} | ||
} |
Oops, something went wrong.