Search in sources :

Example 1 with Header

use of io.micronaut.http.annotation.Header in project micronaut-core by micronaut-projects.

the class HeaderClientRequestBinder method bind.

@Override
public void bind(@NonNull MethodInvocationContext<Object, Object> context, @NonNull ClientRequestUriContext uriContext, @NonNull MutableHttpRequest<?> request) {
    List<AnnotationValue<Header>> headerAnnotations = context.getAnnotationValuesByType(Header.class);
    for (AnnotationValue<Header> headerAnnotation : headerAnnotations) {
        String headerName = headerAnnotation.stringValue("name").orElse(null);
        String headerValue = headerAnnotation.stringValue().orElse(null);
        MutableHttpHeaders headers = request.getHeaders();
        if (StringUtils.isNotEmpty(headerName) && StringUtils.isNotEmpty(headerValue) && !headers.contains(headerName)) {
            headers.set(headerName, headerValue);
        }
    }
}
Also used : Header(io.micronaut.http.annotation.Header) AnnotationValue(io.micronaut.core.annotation.AnnotationValue) MutableHttpHeaders(io.micronaut.http.MutableHttpHeaders)

Aggregations

AnnotationValue (io.micronaut.core.annotation.AnnotationValue)1 MutableHttpHeaders (io.micronaut.http.MutableHttpHeaders)1 Header (io.micronaut.http.annotation.Header)1