Skip to content

Commit

Permalink
Issue #4825 Check method for PushBuilder.
Browse files Browse the repository at this point in the history
Signed-off-by: Jan Bartel <janb@webtide.com>
  • Loading branch information
janbartel committed Apr 29, 2020
1 parent 2fcf0fd commit fa758c2
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

package org.eclipse.jetty.server;

import java.util.EnumSet;
import java.util.Objects;
import java.util.Set;
import javax.servlet.http.PushBuilder;

Expand All @@ -27,6 +29,7 @@
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpURI;
import org.eclipse.jetty.http.MetaData;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.URIUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -39,6 +42,13 @@ public class PushBuilderImpl implements PushBuilder
private static final Logger LOG = LoggerFactory.getLogger(PushBuilderImpl.class);

private static final HttpField JettyPush = new HttpField("x-http2-push", "PushBuilder");
private static EnumSet<HttpMethod> UNSAFE_METHODS = EnumSet.of(
HttpMethod.POST,
HttpMethod.PUT,
HttpMethod.DELETE,
HttpMethod.CONNECT,
HttpMethod.OPTIONS,
HttpMethod.TRACE);

private final Request _request;
private final HttpFields.Mutable _fields;
Expand Down Expand Up @@ -70,6 +80,10 @@ public String getMethod()
@Override
public PushBuilder method(String method)
{
Objects.requireNonNull(method);

if (StringUtil.isBlank(method) || UNSAFE_METHODS.contains(HttpMethod.fromString(method)))
throw new IllegalArgumentException("Method not allowed for push: " + method);
_method = method;
return this;
}
Expand Down Expand Up @@ -149,9 +163,6 @@ public PushBuilder path(String path)
@Override
public void push()
{
if (HttpMethod.POST.is(_method) || HttpMethod.PUT.is(_method))
throw new IllegalStateException("Bad Method " + _method);

if (_path == null || _path.length() == 0)
throw new IllegalStateException("Bad Path " + _path);

Expand Down

0 comments on commit fa758c2

Please sign in to comment.