HTTP’s POST parameter submission and upload different from Mojolicious implementation.

For HTTP protocols, we have several different ways of processing, so we have several different processing methods, so there are different processing for the client and server side. Normal ordinary web pages are uploaded to the server. At the time, different processing is mainly used according to the content. The type embodied in different places in the type of Content-Type.

For example, we often use Mojolicious to handle this type of received parameters and content, it will make many people have dizzy, so I am here, based on the protocol head, come to you to introduce what is different when parameters and upload.

The client, such as the parameters of the form of the form in the browser page, the client, such as the parameter of the CURL of the Linux command line, the different parameters of the program interface, the HTTP protocol is uploaded, there will be three different kinds, These are reflected in the three types of Content-Type:

Application / X-WWW-FORM-URLENCODED

Multipart / form-enctype “Multipart / Form-name” first_name “TEPE” text “/> form>

Client:

In Mojo :: UseRagent, consider very week, when you are submitted, you will automatically help you convert it to “Multipart / Form-Test – WrohxContent-Disposition: form-; filename” .bash_history ” …….. The file itself

Server receiving method

Mojolicious thinks very thoughtful when receiving the backend server. It can be parsed in this format. It will be asynchronously. This will not be more memory. This will automatically use a large file to use a object called Mojo :: Upload to handle, We can get through $ Self-> Req-> Upload (‘args_file’); this method gets the object of this content, the object of this content is Mojo :: Asset :: File This object, save file, and get a big file, you can transfer.

Post ‘/ A / B’> Sub {MY $ Self Shift; MY $ UPLOAD $ Self-> Req-> Upload (‘args_file’); MY $ FOO $ Self-> Param (‘Args’); $ Self-> Render (Text> “Hello from $ foo.”);

3. POST’s body content

The last thing is sometimes we doing big file uploads, and submits content. At this time, the entire body is the file body. The parameter image is passed through the URL.

This doesn’t have to grab the head, no conversion, the whole body is a big file.

Client submission:

Let’s take a look at how the client is transmitted at this time. Similarly, we use Mojo :: UseERAGENT as an example.

MY $ UA MOJO :: UseRagent-> New; $ u -> transactor-> add_generator (stream> subs, $ path) @_; $ tx-> req-> content-> asset Mojo :: ask: File-> New (Path> $ PATH));}; $ uA-> post (‘http://www.php-oa.com/a/b’> stream> / root /.bash_history ‘);

Server reception

At this time, how do you receive it on the server?

Post ‘/ A / B’> SUB {MY $ Self Shift; MY $ BODY $ Self-> Req-> Body; My $ FOO $ Self-> Param (‘args’); $ Self-> Render (Text> ” Hello from $ foo. “);

This, we can directly take the body, but this has a small problem. This is overloaded. This Body will save all the files. For example, this uploaded file has 1G, this 1G will account for memory.This situation, Mojolicious does not implement an event to take the file according to the block. Late to have an article uploaded by a big file, you will share my asynchronous storage files in Mojolicious. This user is uploaded, how much?Will not take up more memory. The whole three ways are introduced, everyone must pay attention to distinguish.