You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@trafficserver.apache.org by Mark Moseley <mo...@gmail.com> on 2013/09/18 06:41:08 UTC

Lua Questions for 4.0.1

I'm just beginning to dig into ATS and liking what I'm seeing and I'm very
interested in Lua integration. Details about the Lua API are a bit sparse
though, so I had a few questions. I hate to ask really basic RTFM-ish
question but I've been banging my head against the wall of google and
digging through ATS code.


* I've seen a mention somewhere (maybe on this list) that the Lua API is
essentially a mapping of 'the API' in general. I've been looking over the
SDK docs and trying to match up stuff in there with the bits of Lua in the
examples directory. Any guidance on where to look? All of the terms I can
find to grep from the 'examples' directory are also terms that are super
common throughout the codebase (e.g. url, headers, method, etc), so I've
had no luck so far with that route.

I'm looking at a script that (edited down) does this:

function remap(request)
  url = request:url()
  request.headers['added-bool'] = true
  ...

I'm curious about things like:
  - How would I know to call my function 'remap' (it seems to find this
function automatically)
  - Where does that url() method come from (i.e. where in the regular API
can I find this and what other methods of the request object are there?)
  - Where could I find a description of the request object data structure?


* I'd like to (ab)use the Lua API to do my own remap based on the original
destination address on the ATS server. Is that stashed in the request
object somewhere?


* Are there any other Lua ATS docs kicking around, even if they're in a
very incomplete and/or rough form? I'd love to see anything you might have
and I promise not to complain about its spottiness ;)


Thanks!

Re: Lua Questions for 4.0.1

Posted by James Peach <jp...@apache.org>.
On Sep 17, 2013, at 9:41 PM, Mark Moseley <mo...@gmail.com> wrote:

> I'm just beginning to dig into ATS and liking what I'm seeing and I'm very interested in Lua integration. Details about the Lua API are a bit sparse though, so I had a few questions. I hate to ask really basic RTFM-ish question but I've been banging my head against the wall of google and digging through ATS code.

Yeh sorry, the docs on the Lua plugin don't exist. I think all the features are coveres by the examples though (except perhaps the config override support).

> * I've seen a mention somewhere (maybe on this list) that the Lua API is essentially a mapping of 'the API' in general. I've been looking over the SDK docs and trying to match up stuff in there with the bits of Lua in the examples directory.

It's not a direct mapping. I tried to make it "nicer" and more native in feel than it would if the APIs were just directly mapped.

> Any guidance on where to look? All of the terms I can find to grep from the 'examples' directory are also terms that are super common throughout the codebase (e.g. url, headers, method, etc), so I've had no luck so far with that route.
> 
> I'm looking at a script that (edited down) does this:
> 
> function remap(request)
>   url = request:url()
>   request.headers['added-bool'] = true
>   ...

When you use Lua as a remap plugin, it executes the global "remap" function on each remap request. This is analogous to TSRemapDoRemap().

> 
> I'm curious about things like:
>   - How would I know to call my function 'remap' (it seems to find this function automatically)
>   - Where does that url() method come from (i.e. where in the regular API can I find this and what other methods of the request object are there?)

The remap function is passed a request object which is roughly analogous to TSRemapRequestInfo. The remap examples demonstrate the APIs that are available on this object.

>   - Where could I find a description of the request object data structure?
> 
> 
> * I'd like to (ab)use the Lua API to do my own remap based on the original destination address on the ATS server. Is that stashed in the request object somewhere?

request:url() gives you a copy of the current URL. You probably want to alter this somehow and then set it using request:rewrite().

> * Are there any other Lua ATS docs kicking around, even if they're in a very incomplete and/or rough form? I'd love to see anything you might have and I promise not to complain about its spottiness ;)

Just the examples.

J