vlingo / xoom-http

The VLINGO XOOM platform SDK for Reactive, scalable, high-throughput, and resilient HTTP server supporting RESTful services running on XOOM LATTICE and XOOM ACTORS.
https://vlingo.io
Mozilla Public License 2.0
52 stars 16 forks source link

Support for compressed body POST/PUT media types #78

Closed bwehrle closed 3 years ago

bwehrle commented 3 years ago

Support for these media types is needed: application/x-tar application/zip & application/x-zip-compressed

This will only work the handler accepts a body with a single parameter, of type TBD, in which case that value will contain the compressed data. The receiver will need to decompress the data. This is not the same as gzip transfer encoding (which is also need because JSON is horribly verbose)

Questions:

VaughnVernon commented 3 years ago

@bwehrle Answers:

  1. I think we must support all three Content-Disposition parameter types, but in particular I need Content-Disposition: attachment; filename="filename.jpg" for my use case
  2. I assume binary because that's what a zip format is; if it's not obvious, please expand on your question

FWIW, the zip we are using in this case is going to be tiny because it carries no jars/dlls, etc. Does that change the answer to 2?

I am going based on this SO answer: https://stackoverflow.com/a/33244623

bwehrle commented 3 years ago

Hi @VaughnVernon ,

Here are my follow-up questions for point 1:

For the receiving function, I think having a single "BinaryRequest" object would be the best approach. Since we cannot deserialize this data (it could be decompressed), we can provide functionality that will work for this new type, which will include the data & meta-data (filename, content encoding).

The resource could work like this:

post.body( BinaryRequest.class ).handle( myRequestHandler )

For question 2: I think my question wasn't very good; I think the answer is yes, you must get binary data.

Ideally in a future state we'd accept Request body payloads (ie JSON, etc) ALSO with compression. So there are two cases here, and we'll be working on the first one only, and not handling any decompression.

1: Issue#78

2: Future issue compressed deserializable (JSON) content

VaughnVernon commented 3 years ago

@bwehrle Thanks, Brian. I think I may have confused you a bit in the requirements. Let me clarify.

Did I address everything?

bwehrle commented 3 years ago

Ah, I only addressed the request part so far. There should be some kind of raw Response. This Response needs to avoid the serializer based on its type (like the request part done so far).

I don't like the name Binary, since technically the content type header defines that format of the content, and you could do this to receive just raw data.

I can work this one out this week, it's still missing the response feature.

VaughnVernon commented 3 years ago

@bwehrle You named the request body quite well as RequestData. How's about ResponseData for this one?

bwehrle commented 3 years ago

Hi @VaughnVernon I was reading through the tests and I think the response is well covered already. See: io.vlingo.xoom.http.resource.RequestHandler0Test#simpleHandlerWithBinaryResponse

  @Test
  public void simpleHandlerWithBinaryResponse() {
    byte[] body = {1, 2, 1, 2};
    final RequestHandler0 handler = new RequestHandler0(Method.GET, "/helloworld")
      .handle(() -> withSuccess(Response.of(Created, Body.from(body, Body.Encoding.None))));
    final Response response = handler.execute(Request.method(Method.GET), logger).outcome();

    assertNotNull(handler);
    assertEquals(Method.GET, handler.method);
    assertEquals("/helloworld", handler.path);
    assertEquals(Body.from(body, Body.Encoding.None).binaryContent(), response.entity.binaryContent());
  }

The Response object lets you specify Body & Headers. I think that's good enough for your use case, because the handler needs to create the compressed body content. Let me know & if its good we can close this issue.

VaughnVernon commented 3 years ago

@bwehrle Excellent, thanks!