Methods of using Lua-zlib in Openresty

Source: Internet
Author: User

==================================================================
1. See if Zlib is present in CentOS?
Rpm-qa | grep zlib

Show:
Zlib-devel-1.2.3-29.el6.x86_64
Zlib-1.2.3-29.el6.x86_64

Indicates that it is installed without worrying too much.

====================================================================
2. Installing the CMake Compiler

Yum install-y gcc gcc-c++ make Automake
wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz
TAR-ZXVF cmake-2.8.10.2.tar.gz
CD cmake-2.8.10.2
./bootstrap
Gmake
Gmake Install

Check CMake Installation
CMake--version
Show
CMake version 2.8.10.2
Indicates successful installation
====================================================================
3, download Lua-zlib package, and unzip
Unzip Lua-zlib-master.zip
Cd/usr/local/software/lua-zlib-master

cmake-dlua_include_dir=/usr/local/openresty/luajit/include/luajit-2.1
Make

CP zlib.so/usr/local/openresty/lualib/zlib.so
====================================================================

4. Call in Lua script

 location/test {Default_type text/html; Content_by_lua ' Local zlib = require "zlib" local encoding = Ngx.req.get_he                        Aders () ["content-encoding"]--The post parameter is first executed before receiving the Ngx.req.read_body ();                                If encoding = = "gzip" then local BODY = Ngx.req.get_body_data ()                                        If body then local stream = Zlib.inflate ()                                        Local R=stream (body);                                Ngx.req.set_body_data (R); End Else Ngx.say ("The input content is not gzip compressed.                                "); Ngx.exit (NGX.                        HTTP_OK);  End-output parameter See local args = Ngx.req.get_post_args () for Key Val in pairs (args) do if Type (val) = = "Table" then Ngx.say (table.co                        Ncat (Val, ",")) Else Ngx.say (val) end                End '; }

====================================================================

5, in C # to the module to submit gzip compressed data to the server

private void Button3_Click (object sender, EventArgs e)        {            var url = "Http://192.168.1.100/test";            var BODY = "body= Yellow Sea is my name!" ";            var ret=httputil.posthttpbygzip (URL, body);            Console.WriteLine (ret);        }
<summary>///function: Initiate a POST request to select whether to use body gzip compression at launch///Yellow Sea///Time: 2015-01-02//</ summary>//<param name= "url" ></param>///<param name= "Body" ></param>//                /<returns></returns> public static string Posthttpbygzip (string URL, string body) {                var req = webrequest.create (URL); Req. Method = "POST"; "POST" req.                Timeout = 20000; Req.                ContentType = "application/x-www-form-urlencoded"; Req.                Headers.add ("content-encoding", "gzip"); var reqstream = req.                GetRequestStream ();                var gz = new GZipStream (Reqstream, compressionmode.compress);                var sw = new StreamWriter (GZ, Encoding.UTF8); Sw.                Write (body); Sw.                Close (); Gz.                Close ();                Reqstream.close (); var myresponse = req.                GetResponse (); var sr = New StreamReader (Myresponse.getresponsestream ()); var ret=sr.                ReadToEnd (); Sr.                Close ();                Myresponse.close ();        return ret; }

====================================================================

Summary of issues:

Makefile is a Linux file, for a project with many files, if compiled directly, then we need to use some commands to include all the files. If we make some changes to some of these files, then we need to re-enter these commands. The makefile file is a good solution to this problem, it contains the required commands in this makefile file, and then simply make a step to complete all the steps.

Methods of using Lua-zlib in Openresty

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.