Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
erlendv opened this issue Jul 19, 2019 · 4 comments · May be fixed by #160
Open

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

erlendv opened this issue Jul 19, 2019 · 4 comments · May be fixed by #160

Comments

@erlendv
Copy link

erlendv commented Jul 19, 2019

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

@erlendv erlendv linked a pull request Jul 19, 2019 that will close this issue
11 tasks
@alexellis
Copy link
Member

Hi @erlendv,

Thank you for your suggestion and for providing lots of detail. I could see this as being a useful change for Java users.

I can see that you've followed some of the contribution guide, but there is a part that states that work shouldn't be started until the feature is agreed on with the maintainers.

Given that you've already done the work, let's chat about it here?

Is this a breaking change?

Alex

@erlendv
Copy link
Author

erlendv commented Jul 20, 2019 via email

@erlendv
Copy link
Author

erlendv commented Jul 20, 2019 via email

@magnusja
Copy link

Any news on this? Cant be true that I can only exchange strings in functions right? Base64 encoding an image adds a substantial overhead I would like to avoid...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants