From 4053d1b5571dfa43b1eaa86b94d40993d3bf8f8c Mon Sep 17 00:00:00 2001 From: Santiago Pericas-Geertsen Date: Tue, 14 Nov 2023 13:22:35 -0500 Subject: [PATCH] Updates header type hierarchy to make HeaderValueCached not writeable. Separates base header classes into writeable and non-writeable. Prevents unnecessary copying of cached headers. (#8000) --- .../io/helidon/http/HeaderValueArray.java | 2 +- .../java/io/helidon/http/HeaderValueBase.java | 5 +--- .../io/helidon/http/HeaderValueCached.java | 5 ---- .../java/io/helidon/http/HeaderValueCopy.java | 2 +- .../java/io/helidon/http/HeaderValueLazy.java | 2 +- .../java/io/helidon/http/HeaderValueList.java | 2 +- .../io/helidon/http/HeaderValueSingle.java | 2 +- .../helidon/http/HeaderWritableValueBase.java | 24 +++++++++++++++++++ 8 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 http/http/src/main/java/io/helidon/http/HeaderWritableValueBase.java diff --git a/http/http/src/main/java/io/helidon/http/HeaderValueArray.java b/http/http/src/main/java/io/helidon/http/HeaderValueArray.java index 7ce999dbe31..5e751144a18 100644 --- a/http/http/src/main/java/io/helidon/http/HeaderValueArray.java +++ b/http/http/src/main/java/io/helidon/http/HeaderValueArray.java @@ -19,7 +19,7 @@ import java.util.ArrayList; import java.util.List; -class HeaderValueArray extends HeaderValueBase { +class HeaderValueArray extends HeaderWritableValueBase { private final String[] originalValues; private List values; diff --git a/http/http/src/main/java/io/helidon/http/HeaderValueBase.java b/http/http/src/main/java/io/helidon/http/HeaderValueBase.java index ba12599a775..fde129c706d 100644 --- a/http/http/src/main/java/io/helidon/http/HeaderValueBase.java +++ b/http/http/src/main/java/io/helidon/http/HeaderValueBase.java @@ -25,7 +25,7 @@ import io.helidon.common.mapper.MapperManager; import io.helidon.common.mapper.Value; -abstract class HeaderValueBase implements HeaderWriteable { +abstract class HeaderValueBase implements Header { private static final String[] QUALIFIER = new String[] {"http", "header"}; private final HeaderName name; private final String actualName; @@ -41,9 +41,6 @@ abstract class HeaderValueBase implements HeaderWriteable { this.firstValue = value; } - @Override - public abstract HeaderWriteable addValue(String value); - @Override public String name() { return actualName; diff --git a/http/http/src/main/java/io/helidon/http/HeaderValueCached.java b/http/http/src/main/java/io/helidon/http/HeaderValueCached.java index e97baf4fb5a..eacce16dd79 100644 --- a/http/http/src/main/java/io/helidon/http/HeaderValueCached.java +++ b/http/http/src/main/java/io/helidon/http/HeaderValueCached.java @@ -54,11 +54,6 @@ public void writeHttp1Header(BufferData buffer) { buffer.write(cachedHttp1Header); } - @Override - public HeaderWriteable addValue(String value) { - throw new UnsupportedOperationException("Cannot change values of a cached header " + name()); - } - @Override public List allValues() { return List.of(value); diff --git a/http/http/src/main/java/io/helidon/http/HeaderValueCopy.java b/http/http/src/main/java/io/helidon/http/HeaderValueCopy.java index e833bedf65d..cd5f6d4b619 100644 --- a/http/http/src/main/java/io/helidon/http/HeaderValueCopy.java +++ b/http/http/src/main/java/io/helidon/http/HeaderValueCopy.java @@ -19,7 +19,7 @@ import java.util.ArrayList; import java.util.List; -class HeaderValueCopy extends HeaderValueBase { +class HeaderValueCopy extends HeaderWritableValueBase { private final Header original; private List values; diff --git a/http/http/src/main/java/io/helidon/http/HeaderValueLazy.java b/http/http/src/main/java/io/helidon/http/HeaderValueLazy.java index 25a5d25bd13..ea0d43802a3 100644 --- a/http/http/src/main/java/io/helidon/http/HeaderValueLazy.java +++ b/http/http/src/main/java/io/helidon/http/HeaderValueLazy.java @@ -21,7 +21,7 @@ import io.helidon.common.buffers.LazyString; -class HeaderValueLazy extends HeaderValueBase { +class HeaderValueLazy extends HeaderWritableValueBase { private final LazyString value; private List values; diff --git a/http/http/src/main/java/io/helidon/http/HeaderValueList.java b/http/http/src/main/java/io/helidon/http/HeaderValueList.java index 933b606bc3a..b3b43036d61 100644 --- a/http/http/src/main/java/io/helidon/http/HeaderValueList.java +++ b/http/http/src/main/java/io/helidon/http/HeaderValueList.java @@ -20,7 +20,7 @@ import java.util.Collection; import java.util.List; -class HeaderValueList extends HeaderValueBase { +class HeaderValueList extends HeaderWritableValueBase { private List values; HeaderValueList(HeaderName name, boolean changing, boolean sensitive, Collection values) { diff --git a/http/http/src/main/java/io/helidon/http/HeaderValueSingle.java b/http/http/src/main/java/io/helidon/http/HeaderValueSingle.java index 305dab2fc43..4a6218d53d9 100644 --- a/http/http/src/main/java/io/helidon/http/HeaderValueSingle.java +++ b/http/http/src/main/java/io/helidon/http/HeaderValueSingle.java @@ -19,7 +19,7 @@ import java.util.ArrayList; import java.util.List; -class HeaderValueSingle extends HeaderValueBase { +class HeaderValueSingle extends HeaderWritableValueBase { private final String value; private List values; diff --git a/http/http/src/main/java/io/helidon/http/HeaderWritableValueBase.java b/http/http/src/main/java/io/helidon/http/HeaderWritableValueBase.java new file mode 100644 index 00000000000..41879064b86 --- /dev/null +++ b/http/http/src/main/java/io/helidon/http/HeaderWritableValueBase.java @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2023 Oracle and/or its affiliates. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.helidon.http; + +abstract class HeaderWritableValueBase extends HeaderValueBase implements HeaderWriteable { + + HeaderWritableValueBase(HeaderName name, boolean changing, boolean sensitive, String value) { + super(name, changing, sensitive, value); + } +}