serverWebExchange.getResponse().getHeaders().add(name, value) UnsupportedOperationException

tags: SpringCloud  gateway

unusual phenomenon

Today, modify the value of the ServerWeBexchange response header in Spring Cloud Gateway, and reported the following exception:

java.lang.UnsupportedOperationException: null
	at org.springframework.http.ReadOnlyHttpHeaders.add(ReadOnlyHttpHeaders.java:67) ~[spring-web-5.1.3.RELEASE.jar:5.1.3.RELEASE]

Here is that we use ReadOnlyHttpHeaders, it is only read-only. But when I went to the getHeaders () method of ServerHttpResponse, I found that httpheaders, and httpheaders can be modified; after patient thinking: ServerHttpResponse is submitted to readonlyhttpheaders instead of httpheaders, so give it The following solution:

Abnormal resolution

ServerHttpResponse response = erverWebExchange.getResponse();
response.beforeCommit(() -> {
      response.getHeaders().add(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE);
      return Mono.empty();
});

Intelligent Recommendation

Vue Add NRM Failed THROW New Err_INValid_arg_type (name, 'string', value);

problem Add company to add companies to fail with NRM, errorthrow new ERR_INVALID_ARG_TYPE(name, 'string', value); solve 1, mouse movingTypeErrorFourth line,(C:\Users\zhanshiyu\AppData\Roaming\npm\nod...

Pybind11 pointer int * add (int *, name **) Parameter return value (TCY)

  https://www.pythonheidong.com/blog/article/549621/2c8b4a9c107d312c12c7/ https://blog.csdn.net/zhuikefeng/article/details/107224507...

About UnsupportedOperationException

When using the collection framework encoding, you will often encounter an UnsupportedOperationException. Throws the following exception when executing to list2.add("test"): In the above code...

More Recommendation

Arrays.asList() and UnsupportedOperationException

1. What does Arrays.asList() return? Let's look at the source code asList() returns an ArrayList, but it is not the familiar ArrayList, but the internal class Arrays$ArrayList in the Arrays class. Let...

UnsupportedOperationException exception

UnsupportedOperationException occurs when this code runs Look at the source code to find the reason: the asList() method in the Arrays class It can be seen that this is a fixed size list ArrayList<...

UnsupportedOperationException reason

After using the Arrays.asList() method to convert the array to a list, and adding a piece of data to the list, an UnsupportedOperationException will be reported. The reason is:...

Arrays.asList UnsupportedOperationException

I want to be lazy in the development, and there will be problems in a slight accident, such as this Sao: Abnormal is as follows: Why is this this, look at the source code is very clear: Arrays.aslist ...

UnsupportedOperationExceptionï¼› ImmutableCollections.uoe

Because Method adds @Transactional (readonly = true), build MAP or LIST can't use map.of or list.of, otherwise it will be reported. This is because this way is generated in ImmutableMap or ImmutableLi...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top