Skip to content

Commit 222b7a1

Browse files
committed
Add base64 endpoint
1 parent 3415a3b commit 222b7a1

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Java httpbin supports a subset of httpbin endpoints:
3030
- `/stream-bytes/:n?chunkSize=c&seed=s` Streams _n_ bytes.
3131
- `/delay/:n` Delays responding for _min(n, 10)_ seconds.
3232
- `/bytes/:n` Generates _n_ random bytes of binary data, accepts optional _seed_ integer parameter.
33+
- `/base64/:s` Returns a base64 decoded :s input
3334
- `/cookies` Returns the cookies.
3435
- `/cookies/set?name=value` Sets one or more simple cookies.
3536
- `/cookies/delete?name` Deletes one or more simple cookies.

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,15 @@ baos, new Deflater(Deflater.DEFAULT_COMPRESSION,
556556
}
557557
baseRequest.setHandled(true);
558558
return;
559+
} else if (method.equals("GET") && uri.startsWith("/base64/")) {
560+
Utils.copy(is, Utils.NULL_OUTPUT_STREAM);
561+
byte[] body = Base64.decodeBase64(
562+
uri.substring("/base64/".length()));
563+
servletResponse.setStatus(HttpServletResponse.SC_OK);
564+
os.write(body);
565+
os.flush();
566+
baseRequest.setHandled(true);
567+
return;
559568
} else if (method.equals("GET") && uri.equals("/image/jpeg")) {
560569
Utils.copy(is, Utils.NULL_OUTPUT_STREAM);
561570
servletResponse.setStatus(HttpServletResponse.SC_OK);

0 commit comments

Comments
 (0)