enctype application/json

50 views
Skip to first unread message

Andries

unread,
Dec 24, 2014, 6:55:23 AM12/24/14
to nx...@googlegroups.com
Hi Yaroslav,

are you planning to support enctype application/json in forms? (see http://www.w3.org/TR/html-json-forms/)

Happy holidays!

Yaroslav

unread,
Dec 24, 2014, 7:13:54 AM12/24/14
to nx...@googlegroups.com
Hi Andries,

What exactly do you mean by support? Normally these kinds of things are dealt at application level. Nxweb transfers every enctype transparently.

Yaroslav

--
You received this message because you are subscribed to the Google Groups "nxweb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nxweb+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Andries Arijs

unread,
Dec 24, 2014, 8:35:42 AM12/24/14
to nx...@googlegroups.com
I thought this was server level. I meant parsing of an incoming application/json request. Never mind then :).

Some other question: I like to do some multipart parsing while uploading files. I looked deeper into the upload.c program, but how exactly can I read the input stream and interpret this? In your example you jump to function start_receiving_request_body()

Can you give me a small example on how I can read the input stream?

--
You received this message because you are subscribed to a topic in the Google Groups "nxweb" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nxweb/vhBvobgjscU/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nxweb+un...@googlegroups.com.

Yaroslav

unread,
Dec 24, 2014, 9:38:38 AM12/24/14
to nx...@googlegroups.com
Andries,

There are two ways to handle uploads:

1) The easiest is to let nxweb buffer post data in memory. This is default for all handlers. When on_request callback is called the request body is accessible via req->content pointer (req->content_received holds the size of received data).

If you set NXWEB_PARSE_PARAMETERS flag for your handler (as in hello.c) and request content type is "application/x-www-form-urlencoded" then the content is parsed into parameters while req->content is set to NULL. Do not set NXWEB_PARSE_PARAMETERS flag if you want to parse it yourself.

The only problem with this method is that buffered content cannot exceed NXWEB_MAX_REQUEST_BODY_SIZE, which is 512000 by default.

2) Buffer large requests in disk file, then read it and process. upload.c is the sample. It buffers requests regardless of their size. But you can add simple check in on_post_data():

if (req->content_length<SOME_THRESHOLD)
  // fallback to default in-memory buffering
  return NXWEB_OK;
// otherwise initiate fwbuffer like in upload.c

Full scale example of this approach is python.c module.

You can process uploaded file in your on_request callback. By the time it is called request body is fully buffered, either in memory or in file.

Remember that after receiving request body you have to split it into multipart data, then use base64 decoder. I never done that in C, so have no example available.

Yaroslav


Reply all
Reply to author
Forward
0 new messages