Skip to content

Commit

Permalink
Use the same logic for permitting request body as client.
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeWharton committed Jul 21, 2015
1 parent e52e2b0 commit eeec4b8
Showing 1 changed file with 4 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.squareup.okhttp.internal.framed.FramedStream;
import com.squareup.okhttp.internal.framed.Header;
import com.squareup.okhttp.internal.framed.IncomingStreamHandler;
import com.squareup.okhttp.internal.http.HttpMethod;
import com.squareup.okhttp.internal.ws.RealWebSocket;
import com.squareup.okhttp.internal.ws.WebSocketProtocol;
import com.squareup.okhttp.ws.WebSocketListener;
Expand Down Expand Up @@ -629,19 +630,9 @@ private RecordedRequest readRequest(Socket socket, BufferedSource source, Buffer
}
}

if (request.startsWith("OPTIONS ")
|| request.startsWith("GET ")
|| request.startsWith("HEAD ")
|| request.startsWith("TRACE ")
|| request.startsWith("CONNECT ")) {
if (hasBody) {
throw new IllegalArgumentException("Request must not have a body: " + request);
}
} else if (!request.startsWith("POST ")
&& !request.startsWith("PUT ")
&& !request.startsWith("PATCH ")
&& !request.startsWith("DELETE ")) { // Permitted as spec is ambiguous.
throw new UnsupportedOperationException("Unexpected method: " + request);
String method = request.substring(0, request.indexOf(' '));
if (hasBody && !HttpMethod.permitsRequestBody(method)) {
throw new IllegalArgumentException("Request must not have a body: " + request);
}

return new RecordedRequest(request, headers.build(), chunkSizes, requestBody.receivedByteCount,
Expand Down

0 comments on commit eeec4b8

Please sign in to comment.