Git Product home page Git Product logo

ts-lua's Introduction

Name

ts-lua - Embed the Power of Lua into Apache TrafficServer.

Status

This module is under active development and is production ready.

Version

This document describes ts-lua v0.1.7 released on 31 May 2015. It can work with Apache TrafficServer v4.x, v5.x.

Google group

https://groups.google.com/forum/#!forum/ts-lua

##Synopsis hdr.lua

function send_response()
    ts.client_response.header['Rhost'] = ts.ctx['rhost']
    return 0
end

function do_remap()
    local req_host = ts.client_request.header.Host
    ts.ctx['rhost'] = string.reverse(req_host)
    ts.hook(TS_LUA_HOOK_SEND_RESPONSE_HDR, send_response)
    return 0
end

sethost.lua

local HOSTNAME = ''

function __init__(argtb)
    if (#argtb) < 1 then
        print(argtb[0], 'hostname parameter required!!')
        return -1
    end
    HOSTNAME = argtb[1]
end

function do_remap()
    ts.client_request.header['Host'] = HOSTNAME
    return 0
end

Description

This module embeds Lua, via the standard Lua 5.1 interpreter, into Apache Traffic Server. This module acts as remap plugin of Traffic Server, so we should realize 'do_remap' function in each lua script. We can write this in remap.config:

map http://a.foo.com/ http://inner.foo.com/ @plugin=/X/libtslua.so @pparam=/X/hdr.lua

Sometimes we want to receive parameters and process them in the script, we should realize '_init_' function in the lua script(sethost.lua is a reference), and we can write this in remap.config:

map http://a.foo.com/ http://b.foo.com/ @plugin=/X/libtslua.so @pparam=/X/sethost.lua @pparam=a.st.com

Doc

https://github.com/portl4t/ts-lua/wiki/Doc

System Requirements

  • linux/freebsd 64bits
  • trafficserver
  • pcre
  • tcl
  • openssl
  • lua-5.1

Build

step1: get ts-lua

git clone https://github.com/portl4t/ts-lua.git
cd ts-lua/src

step2: modify Makefile to insure INC_PATH and LIB_PATH is right for trafficserver, lua-5.1 and tcl

make

step3: modify remap.config and restart the trafficserver

ChangeLog

https://github.com/portl4t/ts-lua/wiki/ChangeLog

History

See Also

  • ts-fetcher http fetcher for ats, implement as plugin with c

ts-lua's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.