Commit graph

16 commits

Author SHA1 Message Date
Earl Warren ec8f162b33
[BRANDING] add X-Forgejo-* headers
(cherry picked from commit 0a3388f93f53f53cce79ebcc194d67979cbe61cc)
(cherry picked from commit 7eba0a440a3138443d0b7461560f9f6f1c46b256)
(cherry picked from commit eb9646c7ef0b1a9e73bf22806acbc2caeaee7ff3)
(cherry picked from commit f1972578f5cb72ad9e1ef1ded9aa324b1d669864)

Conflicts:
(cherry picked from commit 7f96222fb4b4a773193a11d4ba76f449013c30ef)
(cherry picked from commit e3c7c9fe7b5809cdb75f1eb629c82b27986f7e98)
(cherry picked from commit 84fdead90242e68493efb96a7fee1e3b5fd417e9)
(cherry picked from commit 85148e11961b86269b7cda30294a4cdc817787d0)
(cherry picked from commit c0086bd70d39d9a1075fa624cdbfdf5ef26f7a2c)
(cherry picked from commit d1e31ef31817e5e811f6bea7aee5582383d53b12)
(cherry picked from commit 681d3ed5c43d45f802dc13c58c5b821da938374d)
(cherry picked from commit 76a3001f5bc5a064054514c179ba14008952e914)
(cherry picked from commit a55a9567d36f6b60557df3df3a0801c0fccec963)
(cherry picked from commit aa7adc167d4e4ee7879b88fe799f2afca2fd5531)
(cherry picked from commit d5354cb52c26ab0090388d019efe61770e7ec452)
(cherry picked from commit 472c48999699420d15aaa7c61a42db8136221616)
(cherry picked from commit dc816d065b715f2bfdc7fa68fa2d254f3d481b35)
(cherry picked from commit 4795f9ea85eac21c70db1159914a7b7b035b7374)
(cherry picked from commit ddd4ae53433d4adab823aa974c0f1c39d0394414)
(cherry picked from commit 0e95f2a36b1c0f480f94fef85d341792c7a7b759)
(cherry picked from commit 47a41a4e7b3c5d3cf247dafef17a64415069f171)
(cherry picked from commit d4416fcd3ee0f1d74c2b03fbe40c15b83f80b56d)
(cherry picked from commit f279d153b61677e2a766859c7a7688b0327e7c9a)
(cherry picked from commit 959f908ffdc9dd2fb07aefdf7cb85ba34f9071a3)
(cherry picked from commit 82df95310176a083abb9eaa51de9e9754d4f72c6)
(cherry picked from commit 8f8c9fd9e3deca0af0f087fc44fcd271e8440a7b)
(cherry picked from commit d4a0db7706f30a394192c6023072ad5185a7d600)
(cherry picked from commit 44594d623942128072bd86a20b5b90603517005e)
(cherry picked from commit 62b1de579ebfe326340b218cc9a980b705b8e6a2)
(cherry picked from commit 507abee353f120247276fe9165f09976421f926d)
(cherry picked from commit 8c36ac42c7091661b2f3fec70fc88a74043628fc)
(cherry picked from commit 72f74067f4c781e1c4936f0da2653a35a6f1c82b)
(cherry picked from commit 8e5a9e187b50a6eb8523c6dda4ce1a23c08a0b5a)
(cherry picked from commit cff8f43c7e4ab86a468ea49f7b945412d9911151)
(cherry picked from commit 493cc93e6d4b738a5b81d1a0db831bf9f430e9de)
(cherry picked from commit c94352b4d460e631c223b45516e42765357bf67d)
(cherry picked from commit 3f622c51a70200bf67d209d0cec78db2f25b65db)
(cherry picked from commit 84c62ad447a94ebd5d1906e41c29efd3a0816c70)
(cherry picked from commit ba186c8ee40e95cd4f40b6205d673dfe20528825)
(cherry picked from commit 4238ef291dffb68b350aa2f410e934d52cb0a1eb)
(cherry picked from commit 3ef1bd61b9a45271e69c1529875e84b379073318)
(cherry picked from commit f304086bb693d3a0a58871ba8cb1354ba290695c)
(cherry picked from commit 64a2edabcb7bc9e3961ea45f83cf6488e4cd99f2)
(cherry picked from commit 6accea6ba7f2b0f98b6bef5b1483ee39ad68edba)
(cherry picked from commit 2296e93a42939af90dee718bc8ff691009238c47)
(cherry picked from commit 2bf0be3b1bff62923dd04e1a02956ced1eda97af)
(cherry picked from commit fb4652b197ec64280689e6d065492f916f7e26f3)
(cherry picked from commit 7d462cf353ef87007025bbd76aebef429be10562)
(cherry picked from commit f5319660ddecea208163b5bcd37444322e571b51)
2024-02-05 16:02:14 +01:00
cchangwen 28fe3db1fb
Also match weakly validated ETags (#28957)
https://stackoverflow.com/questions/51973120/where-does-the-w-in-an-etag-appear-from

https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag#

---------

Co-authored-by: delvh <dev.lh@web.de>
2024-01-29 16:18:40 +00:00
6543 8995046110
Less naked returns (#25713)
just a step towards  #25655

and some related refactoring
2023-07-07 05:31:56 +00:00
wxiaoguang a94a8d0ab1
Use standard HTTP library to serve files (#24693)
`http.ServeFile/ServeContent` handles `If-xxx`, `Content-Length`,
`Range` and `Etag` correctly

After this PR, storage files (eg: avatar) could be responded with
correct Content-Length.
2023-05-13 16:04:57 +02:00
Yarden Shoham af0468ed8d
Set X-Gitea-Debug header once (#23361)
Instead of adding it

# Before
On the raw commit page:

![image](https://user-images.githubusercontent.com/20454870/223470744-cdf11898-e023-4198-8c8b-c294e5d78b73.png)

# After

![image](https://user-images.githubusercontent.com/20454870/223470596-af898d66-bd5b-4ddb-b220-ceb1f149bfec.png)

Fixes #23308

---------

Signed-off-by: Yarden Shoham <hrsi88@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
2023-03-08 15:40:04 -05:00
wxiaoguang ccb3851281
Add some comments for recent code (#22725)
When using the main branch, I found that some changed code didn't have
comments.

This PR adds some comments.
2023-02-02 11:39:38 -06:00
Brecht Van Lommel 1e0e79dcbf
Fix cache-control header clearing comment text when editing issue (#22604)
The `no-store` cache control added in #20432 is causing form input to be
cleared unnecessarily on page reload. Instead use
`max-age=0,private,must-revalidate` which avoids this.

This was particularly a problem when typing a long comment for an issue
and then for example changing the label. The page would be reloaded and
lose the unsubmitted comment.

Fixes #22603
2023-02-01 15:28:06 -06:00
flynnnnnnnnnn e81ccc406b
Implement FSFE REUSE for golang files (#21840)
Change all license headers to comply with REUSE specification.

Fix #16132

Co-authored-by: flynnnnnnnnnn <flynnnnnnnnnn@github>
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
2022-11-27 18:20:29 +00:00
silverwind 14178c56bb
Add Cache-Control header to html and api responses, add no-transform (#20432)
`no-transform` allegedly disables CloudFlare auto-minify and we did not
set caching headers on html or api requests, which seems good to have
regardless.

Transformation is still allowed for asset requests.

Signed-off-by: Andrew Thornton <art27@cantab.net>

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Co-authored-by: Andrew Thornton <art27@cantab.net>
2022-07-23 14:38:03 +08:00
zeripath 9f5ddca57c
Set the LastModified header for raw files (#18356)
Although the use of LastModified dates for caching of git objects should be
discouraged (as it is not native to git - and there are a LOT of ways this
could be incorrect) - LastModified dates can be a helpful somewhat more human
way of caching for simple cases.

This PR adds this header and handles the If-Modified-Since header to the /raw/
routes.

Fix #18354

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: 6543 <6543@obermui.de>
2022-05-09 17:54:51 +02:00
6543 54e9ee37a7
format with gofumpt (#18184)
* gofumpt -w -l .

* gofumpt -w -l -extra .

* Add linter

* manual fix

* change make fmt
2022-01-20 18:46:10 +01:00
Lunny Xiao f494776931
Use a variable but a function for IsProd because of a slight performance increment (#17368) 2021-10-20 16:37:19 +02:00
wxiaoguang f0ba87fda8
Avatar refactor, move avatar code from models to models.avatars, remove duplicated code (#17123)
Why this refactor

The goal is to move most files from `models` package to `models.xxx` package. Many models depend on avatar model, so just move this first.

And the existing logic is not clear, there are too many function like `AvatarLink`, `RelAvatarLink`, `SizedRelAvatarLink`, `SizedAvatarLink`, `MakeFinalAvatarURL`, `HashedAvatarLink`, etc. This refactor make everything clear:

* user.AvatarLink()
* user.AvatarLinkWithSize(size)
* avatars.GenerateEmailAvatarFastLink(email, size)
* avatars.GenerateEmailAvatarFinalLink(email, size)

And many duplicated code are deleted in route handler, the handler and the model share the same avatar logic now.
2021-10-06 01:25:46 +02:00
KN4CK3R a35a5b225c
Add ETag header (#15370)
* Add ETag header.

* Comply with RFC 7232.

* Moved logic into httpcache.go

* Changed name.

* Lint

* Implemented If-None-Match list.

* Fixed missing header on *

* Removed weak etag support.

* Removed * support.

* Added unit test.

* Lint

Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2021-04-12 10:49:26 -04:00
Lunny Xiao 84b147c7f0
Use IsProd instead of testing if it's equal. (#14336)
Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: zeripath <art27@cantab.net>
2021-01-14 23:17:03 +02:00
silverwind 0615b668dc
HTTP cache rework and enable caching for storage assets (#13569)
This enabled HTTP time-based cache for storage assets, primarily
avatars. I have not observed If-Modified-Since from browsers during
tests but I guess it's good to support regardless.

It introduces a new generic httpcache module that can handle both
time-based and etag-based caching.

Additionally, manifest.json and robots.txt are now also cachable.
2020-11-17 17:44:52 -05:00