You are viewing a plain text version of this content. The canonical link for it is here.
Posted to docs@httpd.apache.org by William A Rowe Jr <wr...@rowe-clan.net> on 2018/11/14 17:09:07 UTC

Re: [users@httpd] RewriteMap prg: How to pass value from Python3 script back to Apache24?

Since the documentation offered uses an example of invoking a .pl script,
the docs are clearly wrong with respect to this feature. It is likely a
regression
which changed when the option to specify the user/group was added.


On Tue, Nov 13, 2018 at 3:06 PM Benedikt Kroll <
benedikt.kroll@der-arbeitende.de> wrote:

> The solution I just found is the following: Even though the python
> script has the necessary execute permissions, the RewriteMap definition
> required that the python interpreter is included in the Apache config file:
>
> RewriteMap extrw "prg:/usr/bin/python3 /opt/extrw.py"
>
> Now it worked using this script:
>
> while True:
>       arg = sys.stdin.readline() # makes sense, but will work without
>       newValue = "/index.html" # placeholder for testing
>       sys.stdout.write(newValue + "\n")
>       sys.stdout.flush()
>
>
>
> Am 10.11.18 um 20:33 schrieb Benedikt Kroll:
> > Hi,
> >
> > using Rewrite Map with MapType prg in Apache 2.4, I'm having trouble
> > passing the value back to Apache.
> >
> > The log says "map lookup OK", but the value is empty.
> >
> > On Stackoverflow and others, I found and tried out some examples, which
> > in some cases where quite old, so probably written for older versions.
> >
> > The following is what I extracted from the more current hints I could
> find.
> >
> >
> > *.conf
> >          RewriteEngine On
> >          RewriteMap extrw "prg:/opt/extrw.py"
> >          RewriteRule "^(.*)" "${extrw:%{REQUEST_URI}}"
> >
> >
> > /opt/extrw.py
> >      import sys
> >      while True:
> >          newValue = "/index.html"  # placeholder for testing
> >          sys.stdout.write(newValue + "/n")
> >          sys.stdout.flush()
> >
> >
> > log for curl 127.0.0.1/abc
> >      init rewrite engine with requested uri /abc
> >      applying pattern '^(.*)' to uri '/abc'
> >      map lookup OK: map=extrw key=/abc -> val=
> >      rewrite '/abc' -> ''
> >      local path result:
> >
> >
> > The expected result would be to have "map lookup OK: map=extrw key=/abc
> > -> val=/index.html" in the third line.
> >
> > Any help would be appreciated!
> >
> > Thanks!
> > Benedikt
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> > For additional commands, e-mail: users-help@httpd.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

Re: [users@httpd] RewriteMap prg: How to pass value from Python3 script back to Apache24?

Posted by William A Rowe Jr <wr...@rowe-clan.net>.
On Wed, Nov 14, 2018 at 11:41 AM Joe Orton <jo...@redhat.com> wrote:

> On Wed, Nov 14, 2018 at 11:09:07AM -0600, William A Rowe Jr wrote:
> > Since the documentation offered uses an example of invoking a .pl script,
> > the docs are clearly wrong with respect to this feature. It is likely a
> > regression
> > which changed when the option to specify the user/group was added.
>
> Gimme a break, "clearly", really??
>
> Working script:
> > >       sys.stdout.write(newValue + "\n")
>
> Non-working script:
> > > >          sys.stdout.write(newValue + "/n")
>
> Spot the difference!  I'll bet $10 the docs are right and the code is
> fine.
>

Ack, examining the error log in the first place might have been more
informative,
I took the python3 invocation feedback verbatim from the post.

Curious, Benedikt, whether the transformation now works, without invoking
the python3 interpreter, now that you've adjusted the script for "\n" line
endings?

In other places such as error logs, we've implemented the users choice
between
invoking the binary, or invoking a shell (allowing us to use shebang line
launching
of scripts.) This is a possibility for the prg: mapping command invocation
as well.

Re: [users@httpd] RewriteMap prg: How to pass value from Python3 script back to Apache24?

Posted by Joe Orton <jo...@redhat.com>.
On Wed, Nov 14, 2018 at 11:09:07AM -0600, William A Rowe Jr wrote:
> Since the documentation offered uses an example of invoking a .pl script,
> the docs are clearly wrong with respect to this feature. It is likely a
> regression
> which changed when the option to specify the user/group was added.

Gimme a break, "clearly", really??

Working script:
> >       sys.stdout.write(newValue + "\n")

Non-working script:
> > >          sys.stdout.write(newValue + "/n")

Spot the difference!  I'll bet $10 the docs are right and the code is 
fine.


---------------------------------------------------------------------
To unsubscribe, e-mail: docs-unsubscribe@httpd.apache.org
For additional commands, e-mail: docs-help@httpd.apache.org