Skip to content

Commit

Permalink
Updates header type hierarchy to make HeaderValueCached not writeable…
Browse files Browse the repository at this point in the history
…. Separates base header classes into writeable and non-writeable. Prevents unnecessary copying of cached headers. (#8000)
  • Loading branch information
spericas authored Nov 14, 2023
1 parent 7e72ac8 commit 4053d1b
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> values;

Expand Down
5 changes: 1 addition & 4 deletions http/http/src/main/java/io/helidon/http/HeaderValueBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> allValues() {
return List.of(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> values;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import io.helidon.common.buffers.LazyString;

class HeaderValueLazy extends HeaderValueBase {
class HeaderValueLazy extends HeaderWritableValueBase {
private final LazyString value;
private List<String> values;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.Collection;
import java.util.List;

class HeaderValueList extends HeaderValueBase {
class HeaderValueList extends HeaderWritableValueBase {
private List<String> values;

HeaderValueList(HeaderName name, boolean changing, boolean sensitive, Collection<String> values) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> values;

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 4053d1b

Please sign in to comment.