@ -1,5 +1,5 @@
@@ -1,5 +1,5 @@
/ *
* Copyright 2002 - 2022 the original author or authors .
* Copyright 2002 - 2024 the original author or authors .
*
* Licensed under the Apache License , Version 2 . 0 ( the "License" ) ;
* you may not use this file except in compliance with the License .
@ -26,10 +26,13 @@ import java.nio.charset.Charset;
@@ -26,10 +26,13 @@ import java.nio.charset.Charset;
import java.security.Principal ;
import java.time.Instant ;
import java.util.AbstractMap ;
import java.util.AbstractSet ;
import java.util.ArrayList ;
import java.util.Arrays ;
import java.util.Collection ;
import java.util.Collections ;
import java.util.Enumeration ;
import java.util.Iterator ;
import java.util.List ;
import java.util.Locale ;
import java.util.Map ;
@ -55,6 +58,7 @@ import org.springframework.http.converter.GenericHttpMessageConverter;
@@ -55,6 +58,7 @@ import org.springframework.http.converter.GenericHttpMessageConverter;
import org.springframework.http.converter.HttpMessageConverter ;
import org.springframework.http.server.RequestPath ;
import org.springframework.http.server.ServletServerHttpRequest ;
import org.springframework.lang.NonNull ;
import org.springframework.lang.Nullable ;
import org.springframework.util.CollectionUtils ;
import org.springframework.util.LinkedMultiValueMap ;
@ -73,6 +77,7 @@ import org.springframework.web.util.UriBuilder;
@@ -73,6 +77,7 @@ import org.springframework.web.util.UriBuilder;
*
* @author Arjen Poutsma
* @author Sam Brannen
* @author Patrick Strawderman
* @since 5 . 2
* /
class DefaultServerRequest implements ServerRequest {
@ -433,18 +438,77 @@ class DefaultServerRequest implements ServerRequest {
@@ -433,18 +438,77 @@ class DefaultServerRequest implements ServerRequest {
@Override
public void clear ( ) {
List < String > attributeNames = Collections . list ( this . servletRequest . getAttributeNames ( ) ) ;
attributeNames . forEach ( this . servletRequest : : removeAttribute ) ;
this . servletRequest . getAttributeNames ( ) . asIterator ( ) . forEachRemaining ( this . servletRequest : : removeAttribute ) ;
}
@Override
public Set < Entry < String , Object > > entrySet ( ) {
return Collections . list ( this . servletRequest . getAttributeNames ( ) ) . stream ( )
. map ( name - > {
Object value = this . servletRequest . getAttribute ( name ) ;
return new SimpleImmutableEntry < > ( name , value ) ;
} )
. collect ( Collectors . toSet ( ) ) ;
return new AbstractSet < > ( ) {
@Override
public Iterator < Entry < String , Object > > iterator ( ) {
return new Iterator < > ( ) {
private final Iterator < String > attributes = ServletAttributesMap . this . servletRequest . getAttributeNames ( ) . asIterator ( ) ;
@Override
public boolean hasNext ( ) {
return this . attributes . hasNext ( ) ;
}
@Override
public Entry < String , Object > next ( ) {
String attribute = this . attributes . next ( ) ;
Object value = ServletAttributesMap . this . servletRequest . getAttribute ( attribute ) ;
return new SimpleImmutableEntry < > ( attribute , value ) ;
}
} ;
}
@Override
public boolean isEmpty ( ) {
return ServletAttributesMap . this . isEmpty ( ) ;
}
@Override
public int size ( ) {
return ServletAttributesMap . this . size ( ) ;
}
@Override
public boolean contains ( Object o ) {
if ( ! ( o instanceof Map . Entry < ? , ? > entry ) ) {
return false ;
}
String attribute = ( String ) entry . getKey ( ) ;
Object value = ServletAttributesMap . this . servletRequest . getAttribute ( attribute ) ;
return value ! = null & & value . equals ( entry . getValue ( ) ) ;
}
@Override
public boolean addAll ( @NonNull Collection < ? extends Entry < String , Object > > c ) {
throw new UnsupportedOperationException ( ) ;
}
@Override
public boolean remove ( Object o ) {
throw new UnsupportedOperationException ( ) ;
}
@Override
public boolean removeAll ( Collection < ? > c ) {
throw new UnsupportedOperationException ( ) ;
}
@Override
public boolean retainAll ( @NonNull Collection < ? > c ) {
throw new UnsupportedOperationException ( ) ;
}
@Override
public void clear ( ) {
throw new UnsupportedOperationException ( ) ;
}
} ;
}
@Override
@ -467,6 +531,22 @@ class DefaultServerRequest implements ServerRequest {
@@ -467,6 +531,22 @@ class DefaultServerRequest implements ServerRequest {
this . servletRequest . removeAttribute ( name ) ;
return value ;
}
@Override
public int size ( ) {
Enumeration < String > attributes = this . servletRequest . getAttributeNames ( ) ;
int size = 0 ;
while ( attributes . hasMoreElements ( ) ) {
size + + ;
attributes . nextElement ( ) ;
}
return size ;
}
@Override
public boolean isEmpty ( ) {
return ! this . servletRequest . getAttributeNames ( ) . hasMoreElements ( ) ;
}
}