001/*
002 * Copyright 2002-2018 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.web.bind.annotation;
018
019import java.lang.annotation.Documented;
020import java.lang.annotation.ElementType;
021import java.lang.annotation.Retention;
022import java.lang.annotation.RetentionPolicy;
023import java.lang.annotation.Target;
024
025import org.springframework.core.annotation.AliasFor;
026
027/**
028 * Annotation which indicates that a method parameter should be bound to a web request header.
029 *
030 * <p>Supported for annotated handler methods in Spring MVC and Spring WebFlux.
031 *
032 * <p>If the method parameter is {@link java.util.Map Map&lt;String, String&gt;},
033 * {@link org.springframework.util.MultiValueMap MultiValueMap&lt;String, String&gt;},
034 * or {@link org.springframework.http.HttpHeaders HttpHeaders} then the map is
035 * populated with all header names and values.
036 *
037 * @author Juergen Hoeller
038 * @author Sam Brannen
039 * @since 3.0
040 * @see RequestMapping
041 * @see RequestParam
042 * @see CookieValue
043 */
044@Target(ElementType.PARAMETER)
045@Retention(RetentionPolicy.RUNTIME)
046@Documented
047public @interface RequestHeader {
048
049        /**
050         * Alias for {@link #name}.
051         */
052        @AliasFor("name")
053        String value() default "";
054
055        /**
056         * The name of the request header to bind to.
057         * @since 4.2
058         */
059        @AliasFor("value")
060        String name() default "";
061
062        /**
063         * Whether the header is required.
064         * <p>Defaults to {@code true}, leading to an exception being thrown
065         * if the header is missing in the request. Switch this to
066         * {@code false} if you prefer a {@code null} value if the header is
067         * not present in the request.
068         * <p>Alternatively, provide a {@link #defaultValue}, which implicitly
069         * sets this flag to {@code false}.
070         */
071        boolean required() default true;
072
073        /**
074         * The default value to use as a fallback.
075         * <p>Supplying a default value implicitly sets {@link #required} to
076         * {@code false}.
077         */
078        String defaultValue() default ValueConstants.DEFAULT_NONE;
079
080}