File tree Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Expand file tree Collapse file tree 2 files changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -222,6 +222,8 @@ func isOSWindows() bool {
222222 return runtime .GOOS == "windows"
223223}
224224
225+ var driveLetterRegexp = regexp .MustCompile ("/[A-Za-z]:/" )
226+
225227// FileURLToPath extracts the path information from a file://... url.
226228func FileURLToPath (u * url.URL ) (string , error ) {
227229 if u .Scheme != "file" {
@@ -235,8 +237,7 @@ func FileURLToPath(u *url.URL) (string, error) {
235237 }
236238
237239 // If it looks like there's a Windows drive letter at the beginning, strip off the leading slash.
238- re := regexp .MustCompile ("/[A-Za-z]:/" )
239- if re .MatchString (path ) {
240+ if driveLetterRegexp .MatchString (path ) {
240241 return path [1 :], nil
241242 }
242243 return path , nil
Original file line number Diff line number Diff line change @@ -77,6 +77,8 @@ func CheckAcceptMediaType(ctx *context.Context) {
7777 }
7878}
7979
80+ var rangeHeaderRegexp = regexp .MustCompile (`bytes=(\d+)\-(\d*).*` )
81+
8082// DownloadHandler gets the content from the content store
8183func DownloadHandler (ctx * context.Context ) {
8284 rc := getRequestContext (ctx )
@@ -92,8 +94,7 @@ func DownloadHandler(ctx *context.Context) {
9294 toByte = meta .Size - 1
9395 statusCode := http .StatusOK
9496 if rangeHdr := ctx .Req .Header .Get ("Range" ); rangeHdr != "" {
95- regex := regexp .MustCompile (`bytes=(\d+)\-(\d*).*` )
96- match := regex .FindStringSubmatch (rangeHdr )
97+ match := rangeHeaderRegexp .FindStringSubmatch (rangeHdr )
9798 if len (match ) > 1 {
9899 statusCode = http .StatusPartialContent
99100 fromByte , _ = strconv .ParseInt (match [1 ], 10 , 32 )
You can’t perform that action at this time.
0 commit comments