Skip to content

Commit 1b159d1

Browse files
committed
Added header value transformation method to MessageSupport
1 parent 2d52e37 commit 1b159d1

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

httpcore5-h2/src/main/java/org/apache/hc/core5/http2/priority/PriorityParser.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ public static PriorityValue parse(final Header header) {
5050
if (header == null) {
5151
return PriorityValue.defaults();
5252
}
53-
final PriorityValue[] out = new PriorityValue[1];
54-
MessageSupport.parseHeader(header, (seq, cur) -> out[0] = parse(seq, cur));
55-
return out[0] != null ? out[0] : PriorityValue.defaults();
53+
return MessageSupport.parserHeaderValue(header, PriorityParser::parse);
5654
}
5755

5856
public static PriorityValue parse(final String headerValue) {

httpcore5/src/main/java/org/apache/hc/core5/http/message/MessageSupport.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import java.util.Set;
3737
import java.util.TreeSet;
3838
import java.util.function.BiConsumer;
39+
import java.util.function.BiFunction;
3940
import java.util.function.Consumer;
4041
import java.util.function.UnaryOperator;
4142

@@ -202,6 +203,23 @@ public static void parseHeader(final Header header, final BiConsumer<CharSequenc
202203
}
203204
}
204205

206+
/**
207+
* @since 5.5
208+
*/
209+
public static <T> T parserHeaderValue(final Header header, final BiFunction<CharSequence, ParserCursor, T> transformation) {
210+
Args.notNull(header, "Header");
211+
if (header instanceof FormattedHeader) {
212+
final CharArrayBuffer buf = ((FormattedHeader) header).getBuffer();
213+
final ParserCursor cursor = new ParserCursor(0, buf.length());
214+
cursor.updatePos(((FormattedHeader) header).getValuePos());
215+
return transformation.apply(buf, cursor);
216+
} else {
217+
final String value = header.getValue();
218+
final ParserCursor cursor = new ParserCursor(0, value.length());
219+
return transformation.apply(value, cursor);
220+
}
221+
}
222+
205223
/**
206224
* @since 5.4
207225
*/

0 commit comments

Comments
 (0)