项目作者: Informatievlaanderen

项目描述 :
ASP.NET Core MVC Middleware to add a 'x-basisregister-version' header to the response containing the assembly version.
高级语言: C#
项目地址: git://github.com/Informatievlaanderen/version-header-middleware.git
创建时间: 2018-12-15T14:40:04Z
项目社区:https://github.com/Informatievlaanderen/version-header-middleware

开源协议:MIT License

下载


Be.Vlaanderen.Basisregisters.AspNetCore.Mvc.Middleware.AddVersionHeader Build Status

Goal

Middleware component which adds the version of the assembly as header x-basisregister-version to the response.

It is also possible to configure a custom header name to be used.

Usage

Default x-version header

  1. namespace Example
  2. {
  3. using System.Threading.Tasks;
  4. using Be.Vlaanderen.Basisregisters.AspNetCore.Mvc.Middleware;
  5. using Microsoft.AspNetCore.Builder;
  6. using Microsoft.AspNetCore.Hosting;
  7. using Microsoft.AspNetCore.Http;
  8. using Microsoft.Extensions.Hosting;
  9. public class Program
  10. {
  11. public static async Task Main(string[] args)
  12. {
  13. var builder = Host.CreateDefaultBuilder(args)
  14. .ConfigureWebHostDefaults(x => x.UseStartup<Startup>());
  15. await builder.RunConsoleAsync();
  16. }
  17. }
  18. public class Startup
  19. {
  20. public void Configure(IApplicationBuilder app)
  21. {
  22. app
  23. .UseMiddleware<AddVersionHeaderMiddleware>()
  24. .Run(async context => await context.Response.WriteAsync("Hello World"));
  25. }
  26. }
  27. }

Running this and making a request to it will result in:

  1. $ curl -v localhost:5000
  2. * Rebuilt URL to: localhost:5000/
  3. * Trying 127.0.0.1...
  4. * Connected to localhost (127.0.0.1) port 5000 (#0)
  5. > GET / HTTP/1.1
  6. > Host: localhost:5000
  7. > User-Agent: curl/7.47.0
  8. > Accept: */*
  9. >
  10. < HTTP/1.1 200 OK
  11. < Date: Mon, 13 Jul 2020 21:01:57 GMT
  12. < Server: Kestrel
  13. < Transfer-Encoding: chunked
  14. < x-version: 1.0.0.0
  15. <
  16. Hello World

Custom header

  1. namespace Example
  2. {
  3. using System.Threading.Tasks;
  4. using Be.Vlaanderen.Basisregisters.AspNetCore.Mvc.Middleware;
  5. using Microsoft.AspNetCore.Builder;
  6. using Microsoft.AspNetCore.Hosting;
  7. using Microsoft.AspNetCore.Http;
  8. using Microsoft.Extensions.Hosting;
  9. public class Program
  10. {
  11. public static async Task Main(string[] args)
  12. {
  13. var builder = Host.CreateDefaultBuilder(args)
  14. .ConfigureWebHostDefaults(x => x.UseStartup<Startup>());
  15. await builder.RunConsoleAsync();
  16. }
  17. }
  18. public class Startup
  19. {
  20. public void Configure(IApplicationBuilder app)
  21. {
  22. app
  23. .UseMiddleware<AddVersionHeaderMiddleware>("x-your-custom-header")
  24. .Run(async context => await context.Response.WriteAsync("Hello World"));
  25. }
  26. }
  27. }

Running this and making a request to it will result in:

  1. $ curl -v localhost:5000
  2. * Rebuilt URL to: localhost:5000/
  3. * Trying 127.0.0.1...
  4. * Connected to localhost (127.0.0.1) port 5000 (#0)
  5. > GET / HTTP/1.1
  6. > Host: localhost:5000
  7. > User-Agent: curl/7.47.0
  8. > Accept: */*
  9. >
  10. < HTTP/1.1 200 OK
  11. < Date: Mon, 13 Jul 2020 21:01:57 GMT
  12. < Server: Kestrel
  13. < Transfer-Encoding: chunked
  14. < x-your-custom-header: 1.0.0.0
  15. <
  16. Hello World

License

MIT License

Credits

Languages & Frameworks

  • .NET Core - MIT
  • .NET Core Runtime - CoreCLR is the runtime for .NET Core. It includes the garbage collector, JIT compiler, primitive data types and low-level classes. - MIT
  • .NET Core APIs - CoreFX is the foundational class libraries for .NET Core. It includes types for collections, file systems, console, JSON, XML, async and many others. - MIT
  • .NET Core SDK - Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI. - MIT
  • Roslyn and C# - The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs. - Apache License 2.0
  • F# - The F# Compiler, Core Library & Tools - MIT
  • F# and .NET Core - F# and .NET Core SDK working together. - MIT

Libraries

Tooling

Flemish Government Libraries