Git Product home page Git Product logo

cumpsd / version-header-middleware Goto Github PK

View Code? Open in Web Editor NEW

This project forked from informatievlaanderen/version-header-middleware

0.0 2.0 0.0 850 KB

ASP.NET Core MVC Middleware to add a 'x-basisregister-version' header to the response containing the assembly version.

Home Page: https://www.nuget.org/packages/Be.Vlaanderen.Basisregisters.AspNetCore.Mvc.Middleware.AddVersionHeader/

License: MIT License

F# 39.71% Shell 6.13% C# 54.16%

version-header-middleware's Introduction

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

namespace Example
{
    using System.Threading.Tasks;
    using Be.Vlaanderen.Basisregisters.AspNetCore.Mvc.Middleware;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Http;
    using Microsoft.Extensions.Hosting;

    public class Program
    {
        public static async Task Main(string[] args)
        {
            var builder = Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(x => x.UseStartup<Startup>());

            await builder.RunConsoleAsync();
        }
    }

    public class Startup
    {
        public void Configure(IApplicationBuilder app)
        {
            app
                .UseMiddleware<AddVersionHeaderMiddleware>()
                .Run(async context => await context.Response.WriteAsync("Hello World"));
        }
    }
}

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

$ curl -v localhost:5000
* Rebuilt URL to: localhost:5000/
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 5000 (#0)
> GET / HTTP/1.1
> Host: localhost:5000
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Mon, 13 Jul 2020 21:01:57 GMT
< Server: Kestrel
< Transfer-Encoding: chunked
< x-version: 1.0.0.0
<
Hello World

Custom header

namespace Example
{
    using System.Threading.Tasks;
    using Be.Vlaanderen.Basisregisters.AspNetCore.Mvc.Middleware;
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Http;
    using Microsoft.Extensions.Hosting;

    public class Program
    {
        public static async Task Main(string[] args)
        {
            var builder = Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(x => x.UseStartup<Startup>());

            await builder.RunConsoleAsync();
        }
    }

    public class Startup
    {
        public void Configure(IApplicationBuilder app)
        {
            app
                .UseMiddleware<AddVersionHeaderMiddleware>("x-your-custom-header")
                .Run(async context => await context.Response.WriteAsync("Hello World"));
        }
    }
}

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

$ curl -v localhost:5000
* Rebuilt URL to: localhost:5000/
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 5000 (#0)
> GET / HTTP/1.1
> Host: localhost:5000
> User-Agent: curl/7.47.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Date: Mon, 13 Jul 2020 21:01:57 GMT
< Server: Kestrel
< Transfer-Encoding: chunked
< x-your-custom-header: 1.0.0.0
<
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

  • Paket - A dependency manager for .NET with support for NuGet packages and Git repositories. - MIT
  • FAKE - "FAKE - F# Make" is a cross platform build automation system. - MIT
  • xUnit - xUnit.net is a free, open source, community-focused unit testing tool for the .NET Framework. - Apache License 2.0
  • FluentAssertions - Fluent API for asserting the results of unit tests. - Apache License 2.0

Tooling

Flemish Government Libraries

version-header-middleware's People

Contributors

cumpsd avatar dependabot[bot] avatar ridingwolf avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.