public async Task InvokeAsync(HttpContext context) { if (!context.Request.Path.ToString().ToLower().EndsWith(".png")) { await _next(context); return; } var query = context.Request.Query; var chordName = Regex.Match(context.Request.Path.ToString(), @"^/(.*)\.png$").Groups[1].Value; var pos = query["pos"].FirstOrDefault() ?? query["p"].FirstOrDefault() ?? "000000"; var fingers = query["fingers"].FirstOrDefault() ?? query["f"].FirstOrDefault() ?? "------"; var size = query["size"].FirstOrDefault() ?? query["s"].FirstOrDefault() ?? "1"; context.Response.ContentType = "image/png"; context.Response.GetTypedHeaders().CacheControl = new CacheControlHeaderValue() { Public = true, MaxAge = TimeSpan.FromDays(7) }; var image = new ChordBoxImage(chordName, pos, fingers, size); image.Save(context.Response.Body); }
public void ProcessRequest(HttpContext context) { var request = context.Request; var response = context.Response; var chordName = Regex.Match(request.FilePath, @"^/(.*)\.png$").Groups[1].Value; var qs = request.QueryString; var pos = qs["pos"] ?? qs["p"] ?? "000000"; var fingers = qs["fingers"] ?? qs["f"] ?? "------"; var size = qs["size"] ?? qs["s"] ?? "1"; using (var img = new ChordBoxImage(chordName, pos, fingers, size)) { response.ContentType = "image/png"; response.ExpiresAbsolute = DateTime.Now.AddDays(7); img.Save(context.Response.OutputStream); } }
public void ProcessRequest(HttpContext context) { var request = context.Request; var response = context.Response; var chordName = Regex.Match(request.FilePath, @"^/(.*)\.png$").Groups[1].Value; var qs = request.QueryString; var pos = qs["pos"] ?? qs["p"] ?? "000000"; var fingers = qs["fingers"] ?? qs["f"] ?? "------"; var size = qs["size"] ?? qs["s"] ?? "1"; response.ContentType = "image/png"; response.Cache.SetCacheability(HttpCacheability.Public); response.Cache.SetMaxAge(TimeSpan.FromDays(7)); using (var img = new ChordBoxImage(chordName, pos, fingers, size)) { img.Save(response.OutputStream); } }