26
26
import org .springframework .http .HttpStatus ;
27
27
import org .springframework .lang .Nullable ;
28
28
import org .springframework .util .Assert ;
29
+ import org .springframework .util .CollectionUtils ;
29
30
import org .springframework .util .StringUtils ;
30
31
31
32
/**
@@ -39,7 +40,7 @@ public class MethodNotAllowedException extends ResponseStatusException {
39
40
40
41
private final String method ;
41
42
42
- private final Set <HttpMethod > supportedMethods ;
43
+ private final Set <HttpMethod > httpMethods ;
43
44
44
45
45
46
public MethodNotAllowedException (HttpMethod method , Collection <HttpMethod > supportedMethods ) {
@@ -53,7 +54,7 @@ public MethodNotAllowedException(String method, @Nullable Collection<HttpMethod>
53
54
supportedMethods = Collections .emptySet ();
54
55
}
55
56
this .method = method ;
56
- this .supportedMethods = Collections .unmodifiableSet (new HashSet <>(supportedMethods ));
57
+ this .httpMethods = Collections .unmodifiableSet (new HashSet <>(supportedMethods ));
57
58
}
58
59
59
60
@@ -63,8 +64,9 @@ public MethodNotAllowedException(String method, @Nullable Collection<HttpMethod>
63
64
*/
64
65
@ Override
65
66
public Map <String , String > getHeaders () {
66
- return Collections .singletonMap ("Allow" ,
67
- StringUtils .collectionToDelimitedString (this .supportedMethods , ", " ));
67
+ return !CollectionUtils .isEmpty (this .httpMethods ) ?
68
+ Collections .singletonMap ("Allow" , StringUtils .collectionToDelimitedString (this .httpMethods , ", " )) :
69
+ Collections .emptyMap ();
68
70
}
69
71
70
72
/**
@@ -78,7 +80,7 @@ public String getHttpMethod() {
78
80
* Return the list of supported HTTP methods.
79
81
*/
80
82
public Set <HttpMethod > getSupportedMethods () {
81
- return this .supportedMethods ;
83
+ return this .httpMethods ;
82
84
}
83
85
84
86
}
0 commit comments