Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the possibillity to return custom http response headers based on application.properties #21570

Closed
sjaakd opened this issue Nov 19, 2021 · 5 comments
Labels
kind/enhancement New feature or request triage/duplicate This issue or pull request already exists

Comments

@sjaakd
Copy link

sjaakd commented Nov 19, 2021

Description

The use case for me is to extend the response headers with a semver version notation of the public REST API in a header: API-Version. See a screenshot of FireFox F12-network here:

image

This is driven by the following piece of configuration in application.properties:

application.version=1.0.0

Which could build-time be populated with the maven coordinates.

To make this generic, one could think of the following addition:

quarkus.http.responseheader.<id>.name=API-Version
quarkus.http.responseheader.<id>.value=1.0.0

in a practical case such as this:

quarkus.http.responseheader.apiversion.name=API-Version
quarkus.http.responseheader.apiversion.value=1.0.0

See also: #21457

Implementation ideas

I've used a vertex.RouteFilter to implement this:

public class ApiVersionResponseFilter {

    private static final String API_VERSION_HEADER = "API-Version";

    //CHECKSTYLE:OFF
    @Inject
    ConfigProvider provider;
    //CHECKSTYLE:ON

    @RouteFilter
    public void addResponse(RoutingContext rc) {
            rc.response().headers().set( API_VERSION_HEADER,  provider.version  );
        rc.next();
    }

    @Dependent
    public static class ConfigProvider {

        //CHECKSTYLE:OFF
        @ConfigProperty( name = "application.version" )
        String version;
        //CHECKSTYLE:ON

    }
}
@sjaakd sjaakd added the kind/enhancement New feature or request label Nov 19, 2021
@sjaakd sjaakd changed the title Add the possibillity to return custom http headers based on application.properties Add the possibillity to return custom http response headers based on application.properties Nov 19, 2021
@sberyozkin
Copy link
Member

@gastaldi You have already done it, right ?

@gastaldi
Copy link
Contributor

@gastaldi You have already done it, right ?

Yes, it's documented in https://quarkus.io/version/main/guides/http-reference#additional-http-headers
It is only available in 2.5.0.CR1 onwards (see #21102).

Closing this issue as a duplicate

@gastaldi gastaldi added the triage/duplicate This issue or pull request already exists label Nov 19, 2021
@gastaldi
Copy link
Contributor

FTR this is what you would add in your application.properties :

quarkus.http.header."API-Version".value=${application.version}

@gastaldi
Copy link
Contributor

Or you could avoid the application.version property entirely and use:

quarkus.http.header."API-Version".value=${quarkus.application.version:1.0.0}

quarkus.application.version: The version of the application. If not set, defaults to the version of the project (except for tests where it is not set at all).

@sjaakd
Copy link
Author

sjaakd commented Nov 20, 2021

@gastaldi , @sberyozkin Thanks! This is good news.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/enhancement New feature or request triage/duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants