Skip to content

Commit

Permalink
Message support improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
ok2c committed Sep 23, 2023
1 parent 9f82034 commit c49b787
Show file tree
Hide file tree
Showing 7 changed files with 525 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

import org.apache.hc.core5.annotation.Contract;
import org.apache.hc.core5.annotation.ThreadingBehavior;
import org.apache.hc.core5.http.message.BasicHeaderValueFormatter;
import org.apache.hc.core5.http.message.BasicHeaderValueParser;
import org.apache.hc.core5.http.message.BasicNameValuePair;
import org.apache.hc.core5.http.message.MessageSupport;
import org.apache.hc.core5.http.message.ParserCursor;
import org.apache.hc.core5.util.Args;
import org.apache.hc.core5.util.CharArrayBuffer;
Expand Down Expand Up @@ -284,7 +284,7 @@ public String toString() {
buf.append(this.mimeType);
if (this.params != null) {
buf.append("; ");
BasicHeaderValueFormatter.INSTANCE.formatParameters(buf, this.params, false);
MessageSupport.formatParameters(buf, this.params);
} else if (this.charset != null) {
buf.append("; charset=");
buf.append(this.charset.name());
Expand Down Expand Up @@ -419,9 +419,11 @@ private static ContentType parse(final CharSequence s, final boolean strict) thr
return null;
}
final ParserCursor cursor = new ParserCursor(0, s.length());
final HeaderElement[] elements = BasicHeaderValueParser.INSTANCE.parseElements(s, cursor);
if (elements.length > 0) {
return create(elements[0], strict);
final AtomicReference<HeaderElement> firstElementRef = new AtomicReference<>();
MessageSupport.parseElements(s, cursor, e -> firstElementRef.compareAndSet(null, e));
final HeaderElement element = firstElementRef.get();
if (element != null) {
return create(element, strict);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ public boolean keepAlive(
Args.notNull(response, "HTTP response");

if (request != null) {
final Iterator<String> ti = new BasicTokenIterator(request.headerIterator(HttpHeaders.CONNECTION));
while (ti.hasNext()) {
final String token = ti.next();
final Iterator<String> it = MessageSupport.iterateTokens(request, HttpHeaders.CONNECTION);
while (it.hasNext()) {
final String token = it.next();
if (HeaderElements.CLOSE.equalsIgnoreCase(token)) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import org.apache.hc.core5.http.io.HttpMessageWriter;
import org.apache.hc.core5.http.io.HttpMessageWriterFactory;
import org.apache.hc.core5.http.io.ResponseOutOfOrderStrategy;
import org.apache.hc.core5.http.message.BasicTokenIterator;
import org.apache.hc.core5.http.message.MessageSupport;
import org.apache.hc.core5.util.Args;

/**
Expand Down Expand Up @@ -271,9 +271,9 @@ public void terminateRequest(final ClassicHttpRequest request) throws HttpExcept
if (entity == null) {
return;
}
final Iterator<String> ti = new BasicTokenIterator(request.headerIterator(HttpHeaders.CONNECTION));
while (ti.hasNext()) {
final String token = ti.next();
final Iterator<String> it = MessageSupport.iterateTokens(request, HttpHeaders.CONNECTION);
while (it.hasNext()) {
final String token = it.next();
if (HeaderElements.CLOSE.equalsIgnoreCase(token)) {
this.consistent = false;
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class BasicHeaderElement implements HeaderElement {
public BasicHeaderElement(
final String name,
final String value,
final NameValuePair[] parameters) {
final NameValuePair... parameters) {
super();
this.name = Args.notNull(name, "Name");
this.value = value;
Expand Down
Loading

0 comments on commit c49b787

Please sign in to comment.