Skip to content

Support for binary response and binary request body in java8 template #159

Open
@erlendv

Description

The IResponse interface only have a setBody()/getBody() that works with strings. The entrypoint (com.openfaas.entrypoint.App) also tries to encode the body to UTF-8 when converting to bytes to write to the OutputStream.

Also, the IRequest interface also only have a getBody() that returns a String.

Expected Behaviour

The IResponse-interface should at least have a setBody(byte[] data) and a getBodyData() (that gets the byte). The entrypoint should use getBodyData() instead of getBody().

The best solution would be to write to an OutputStream on the response, ideally being the OutputStream from HttpExchange. getResponseBody().

The IRequest interface should have a getInputStream() method to return an InputStream, and the Request-implementation should return the one from HttpExchange.getRequestBody()

Current Behaviour

Unable to write binary data.

Possible Solution

See expected behaviour.

Steps to Reproduce (for bugs)

Response response = new Response();

ByteArrayOutputStream rawOutputStream = new ByteArrayOutputStream();
ObjectOutputStream objectOutputStream = new ObjectOutputStream(rawOutputStream);

Object resultObject = new Object();
objectOutputStream.writeObject(resultObject);
objectOutputStream.flush();

response.setBody(new String(rawOutputStream.toByteArray())); // have to set the raw data as a String on the response

Context

In my case I was serializing java objects between the function and a java client. Controlling both I base64-encoded the data to work around this. However if the response where to be an image for example it should be possible to return raw data.

Your Environment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions