Move some regexp out of functions (#25430)
/cc @KN4CK3R https://github.com/go-gitea/gitea/pull/25294#discussion_r1237425343 I also searched the codebase and found a few more. --------- Signed-off-by: jolheiser <john.olheiser@gmail.com>
This commit is contained in:
parent
25455bc670
commit
8afc1b1cb5
3 changed files with 9 additions and 7 deletions
|
@ -77,6 +77,8 @@ func CheckAcceptMediaType(ctx *context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
var rangeHeaderRegexp = regexp.MustCompile(`bytes=(\d+)\-(\d*).*`)
|
||||
|
||||
// DownloadHandler gets the content from the content store
|
||||
func DownloadHandler(ctx *context.Context) {
|
||||
rc := getRequestContext(ctx)
|
||||
|
@ -92,8 +94,7 @@ func DownloadHandler(ctx *context.Context) {
|
|||
toByte = meta.Size - 1
|
||||
statusCode := http.StatusOK
|
||||
if rangeHdr := ctx.Req.Header.Get("Range"); rangeHdr != "" {
|
||||
regex := regexp.MustCompile(`bytes=(\d+)\-(\d*).*`)
|
||||
match := regex.FindStringSubmatch(rangeHdr)
|
||||
match := rangeHeaderRegexp.FindStringSubmatch(rangeHdr)
|
||||
if len(match) > 1 {
|
||||
statusCode = http.StatusPartialContent
|
||||
fromByte, _ = strconv.ParseInt(match[1], 10, 32)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue