diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpRequest.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpRequest.java index 7b84919fb72..dc285955578 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpRequest.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpRequest.java @@ -242,6 +242,21 @@ public class HttpRequest implements Request return this; } + @Override + public Request accept(String... accepts) + { + StringBuilder result = new StringBuilder(); + for (String accept : accepts) + { + if (result.length() > 0) + result.append(", "); + result.append(accept); + } + if (result.length() > 0) + headers.put(HttpHeader.ACCEPT, result.toString()); + return this; + } + @Override public Request header(String name, String value) { diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/api/Request.java b/jetty-client/src/main/java/org/eclipse/jetty/client/api/Request.java index 0574dc63bb1..75e45dcfdcc 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/api/Request.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/api/Request.java @@ -230,11 +230,18 @@ public interface Request String getAgent(); /** - * @param agent the user agent for this request + * @param agent the user agent for this request (corresponds to the {@code User-Agent} header) * @return this request object */ Request agent(String agent); + /** + * @param accepts the content types that are acceptable in the response, such as + * "text/plain;q=0.5" or "text/html" (corresponds to the {@code Accept} header) + * @return this request object + */ + Request accept(String... accepts); + /** * @return the idle timeout for this request, in milliseconds */