Wrong response body when using url-encoded contentType in client (v1.0.0)
shashank11p opened this issue · 1 comments
shashank11p commented
Task List
- Steps to reproduce provided
- Example that reproduces the problem given below
- Full description of the issue provided (see below)
Steps to Reproduce
- Create an httpServer that has an endpoint accepting url-encoded content type bodies in request, and return url-encoded body in response
- Create a micronaut DeafultHttpClient and make request to this server with url-encoded body and check response body
Expected Behaviour
Expected response body should have been there. This issue is for micronaut version 1.0.0. It works as expected in micronaut version 2.2.3
Actual Behaviour
empty=false&blank=false
This reponse body was there.
Environment Information
- Operating System: mac
- Micronaut Version: 1.0.0
- JDK Version: 8
Example Application
Test Server : This runs a httpServer that returns the same response body and contentType that was in request on endpoint /echo
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import javax.servlet.ServletInputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.HandlerList;
public class TestHttpServer implements AutoCloseable {
public static final String RESPONSE_HEADER_NAME = "test-response-header";
public static final String RESPONSE_HEADER_VALUE = "test-value";
private final Server server = new Server(0);
private final HandlerList handlerList = new HandlerList();
public void start() throws Exception {
HandlerList handlerList = new HandlerList();
handlerList.addHandler(new EchoHandler());
server.setHandler(handlerList);
server.start();
}
public void addHandler(Handler handler) {
this.handlerList.addHandler(handler);
}
@Override
public void close() throws Exception {
server.stop();
}
public int port() {
return server.getConnectors()[0].getLocalPort();
}
static class ResponseTestHeadersHandler extends AbstractHandler {
@Override
public void handle(
String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response)
throws IOException {
response.setHeader(RESPONSE_HEADER_NAME, RESPONSE_HEADER_VALUE);
}
}
static class EchoHandler extends ResponseTestHeadersHandler {
@Override
public void handle(
String target,
Request baseRequest,
HttpServletRequest request,
HttpServletResponse response)
throws IOException {
super.handle(target, baseRequest, request, response);
if (target.equals("/echo") && "post".equalsIgnoreCase(request.getMethod())) {
ServletInputStream inputStream = request.getInputStream();
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
while ((nRead = inputStream.read()) != -1) {
buffer.write((byte) nRead);
}
response.setStatus(200);
response.setContentType(request.getContentType());
response.getWriter().print(buffer.toString());
baseRequest.setHandled(true);
}
}
}
}
Client code:
MutableHttpRequest<String> request = HttpRequest.POST(uri, "key=value&key2=value2").contentType("application/x-www-form-urlencoded");
HttpResponse<String> response =
client
.toBlocking()
.exchange(request, Argument.of(String.class), HttpClient.DEFAULT_ERROR_TYPE);
jameskleeh commented
There are no plans to release a 1.x version of Micronaut. If this issue is critical, please message me via email or Gitter to discuss other options.