duda icon indicating copy to clipboard operation
duda copied to clipboard

Upload large content & callbacks

Open edsiper opened this issue 10 years ago • 1 comments

Duda stack should support an API to allow the server to listen for large data uploads, where Monkey server after receive the HTTP request headers (on PUT/POST), let Duda handle each incoming data frame.

The API should be something like this:

map->static_upload_stream("/upload", int (*callback)(struct duda_request *dr,  void* buffer, ssize_t len));

so all POST/PUT request with content length > 0 that arrives over /upload URI, will be handled by the callback function which also sets a buffer and a size, that function will be invoked many times until the upload is complete or for some reason the connection is closed.

edsiper avatar Jun 08 '14 20:06 edsiper

Steps to implement feature

This comment is a work in progress.

Monkey

  • Modify HTTP parser to allow stream parsing (maybe use something like Ragel ?)

    Ex:

    parser->request_line_cb = ...;
    parser->header_read_cb = ...;
    void parse_input_data(parser_ctx_t* parser, session_request* sr, void* data, size_t len);
    

    Or just wait for block end and parse whole header block at once

  • Add necessary API hooks (placeholder names)

    • on_headers_ready Could be used to authenticate request before body is sent (fail early), or setup body streaming Must expose an API to enable body chunk callback Return value actions:
      • Abort connection, error response
      • Continue, read request body
    • on_body_chunk_read Receives read body chunks. Return value actions:
      • Abort connection, error response
      • Chunk handled, buffered data can be discarded
      • Chunk handled, continue to buffer data
  • Find all code that expects whole request buffered and work around that

Duda

nalbeza avatar Jun 10 '14 19:06 nalbeza