瀏覽代碼

Convert context value to string securely

DarthSim 5 年之前
父節點
當前提交
65579a5770
共有 2 個文件被更改,包括 6 次插入3 次删除
  1. 4 2
      download.go
  2. 2 1
      processing_options.go

+ 4 - 2
download.go

@@ -210,9 +210,11 @@ func getImageData(ctx context.Context) *imageData {
 }
 }
 
 
 func getCacheControlHeader(ctx context.Context) string {
 func getCacheControlHeader(ctx context.Context) string {
-	return ctx.Value(cacheControlHeaderCtxKey).(string)
+	str, _ := ctx.Value(cacheControlHeaderCtxKey).(string)
+	return str
 }
 }
 
 
 func getExpiresHeader(ctx context.Context) string {
 func getExpiresHeader(ctx context.Context) string {
-	return ctx.Value(expiresHeaderCtxKey).(string)
+	str, _ := ctx.Value(expiresHeaderCtxKey).(string)
+	return str
 }
 }

+ 2 - 1
processing_options.go

@@ -1046,7 +1046,8 @@ func parsePath(ctx context.Context, r *http.Request) (context.Context, error) {
 }
 }
 
 
 func getImageURL(ctx context.Context) string {
 func getImageURL(ctx context.Context) string {
-	return ctx.Value(imageURLCtxKey).(string)
+	str, _ := ctx.Value(imageURLCtxKey).(string)
+	return str
 }
 }
 
 
 func getProcessingOptions(ctx context.Context) *processingOptions {
 func getProcessingOptions(ctx context.Context) *processingOptions {