Skip to content

Commit 3415a3b

Browse files
committed
Loosen content type checking in post endpoint
Fixes #9 and fixes #10.
1 parent d0987fa commit 3415a3b

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/main/java/org/gaul/httpbin/HttpBinHandler.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,8 @@ baos, new Deflater(Deflater.DEFAULT_COMPRESSION,
366366
JSONObject response = new JSONObject();
367367

368368
String contentType = request.getContentType();
369-
if (contentType == null ||
370-
contentType.equals("application/json")) {
371-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
372-
Utils.copy(is, baos);
373-
response.put("data", new String(
374-
baos.toByteArray(), StandardCharsets.UTF_8));
375-
} else if (contentType.startsWith("multipart/form-data")) {
369+
if (contentType != null && contentType.startsWith(
370+
"multipart/form-data")) {
376371
MultiPartInputStreamParser parser =
377372
new MultiPartInputStreamParser(
378373
is, contentType, null, null);
@@ -389,9 +384,10 @@ baos, new Deflater(Deflater.DEFAULT_COMPRESSION,
389384
}
390385
response.put("data", data);
391386
} else {
392-
servletResponse.setStatus(501);
393-
baseRequest.setHandled(true);
394-
return;
387+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
388+
Utils.copy(is, baos);
389+
response.put("data", new String(
390+
baos.toByteArray(), StandardCharsets.UTF_8));
395391
}
396392

397393
response.put("args", mapParametersToJSON(request));

0 commit comments

Comments
 (0)