File tree 2 files changed +6
-4
lines changed 2 files changed +6
-4
lines changed Original file line number Diff line number Diff line change @@ -222,6 +222,8 @@ func isOSWindows() bool {
222
222
return runtime .GOOS == "windows"
223
223
}
224
224
225
+ var driveLetterRegexp = regexp .MustCompile ("/[A-Za-z]:/" )
226
+
225
227
// FileURLToPath extracts the path information from a file://... url.
226
228
func FileURLToPath (u * url.URL ) (string , error ) {
227
229
if u .Scheme != "file" {
@@ -235,8 +237,7 @@ func FileURLToPath(u *url.URL) (string, error) {
235
237
}
236
238
237
239
// 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 ) {
240
241
return path [1 :], nil
241
242
}
242
243
return path , nil
Original file line number Diff line number Diff line change @@ -77,6 +77,8 @@ func CheckAcceptMediaType(ctx *context.Context) {
77
77
}
78
78
}
79
79
80
+ var rangeHeaderRegexp = regexp .MustCompile (`bytes=(\d+)\-(\d*).*` )
81
+
80
82
// DownloadHandler gets the content from the content store
81
83
func DownloadHandler (ctx * context.Context ) {
82
84
rc := getRequestContext (ctx )
@@ -92,8 +94,7 @@ func DownloadHandler(ctx *context.Context) {
92
94
toByte = meta .Size - 1
93
95
statusCode := http .StatusOK
94
96
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 )
97
98
if len (match ) > 1 {
98
99
statusCode = http .StatusPartialContent
99
100
fromByte , _ = strconv .ParseInt (match [1 ], 10 , 32 )
You can’t perform that action at this time.
0 commit comments