-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Add fetch wrappers, ignore network errors in actions view #26985
Conversation
contentType = 'multipart/form-data'; | ||
body = data; | ||
} else if (data instanceof URLSearchParams) { | ||
contentType = 'application/x-www-form-urlencoded'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
multipart/form-data
could be always the correct content type (well, without a file
, application/x-www-form-urlencoded
might be simpler)
While I do not see why it should support URLSearchParams
, the URLSearchParams
should mainly used for URL query string, but not a POST request.
(not blocker)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the backend actually support both encodings interchangbly? Normal form behaviour is application/x-www-form-urlencoded
for forms not containing a file
, and I think the cleanest way for these is to encode them as URLSearchParams
which ensures escaping is correct etc:
* upstream/main: Add more package registry paths to the labeler (go-gitea#27032) Extract auth middleware from service (go-gitea#27028) S3: log human readable error on connection failure (go-gitea#26856) [skip ci] Updated translations via Crowdin Fix "delete" modal dialog for issue/PR (go-gitea#27015) Fix context cache bug & enable context cache for dashabord commits' authors (go-gitea#26991) fix: typo (go-gitea#27009) Use secure cookie for HTTPS sites (go-gitea#26999) Add fetch wrappers, ignore network errors in actions view (go-gitea#26985)
### Fetching data | ||
|
||
To fetch data, use the wrapper functions `GET`, `POST` etc. from `modules/fetch.js`. They | ||
accept a `data` option for the content, will automatically set CSFR token and return a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CSRF
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will fix this in followup #27026.
|
||
return fetch(url, { | ||
headers: { | ||
'x-csrf-token': csrfToken, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are headers case-insensitive?
I've only seen them be called X-Csrf-Token
yet…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, HTTP headers by definition are to be treated case-insensitive while reading them and in fact we should lowercase them all everywhere.
In HTTP2 the common headers are transferred via a mapping table that outputs lowercase: https://datatracker.ietf.org/doc/html/rfc7541#appendix-A
fetch
wrapper functions that automatically sets csfr token, content-type and use it inRepoActionView.vue
.RepoActionView.vue
where a fetch network error is shortly visible during page reload sometimes. It can be reproduced by F5-in in quick succession on the actions view page and was also producing a red error box on the page.Once approved, we can replace all current
fetch
uses in UI with this in another PR.