Q: mod_ruby may be NPH?

I have a trouble with using mod_ruby 1.0.1.
I got the string “Content-Type: text/html” in browser when accessed to
mod_ruby script.

I wrote a script ‘sample.rbx’:
…----------------------------------------
#!/usr/bin/ruby

print “Content-Type: text/html\n\n”

print <<END

mod_ruby test

END ..----------------------------------------

And create a directory htdocs/ruby, and place a script in it.

But I accessed http://localhost:80/ruby/sample.rbx, the string
"Content-Type: text/html" was displayed in browser.

The following is a log accessing by telnet.
…----------------------------------------
$ telnet localhost 80
Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.
GET /ruby/sample.rbx HTTP 1.1

Content-Type: text/html

mod_ruby test

Connection closed by foreign host. ..----------------------------------------

But when executing the script as a CGI, the result is fine.
…----------------------------------------
$ telnet localhost 80
Trying 127.0.0.1…
Connected to localhost.
Escape character is ‘^]’.
GET /cgi-bin/sample.cgi HTTP 1.1

HTTP/1.1 200 OK
Server: Apache/1.3.23 (Unix) (Red-Hat/Linux) mod_ruby/1.0.1 Ruby/1.6.7
Connection: close
Content-Type: text/html

mod_ruby test

Connection closed by foreign host. ..----------------------------------------

I guess that this trouble is due to NPH mode.
If so, please tell me how to change NPH mode off, or another solution.

OS: RedHat Linux 7.3
Apache: 1.3.23 (rpm install)
mod_ruby: 1.0.1 (source compiled)

regards,
kwatch

···

Date: Mon, 25 Nov 2002 13:54:12 GMT

http://www.rubydoc.org/books/modruby/modruby.pdf , chapter 5

r = Apache.request
r.content_type = ‘text/html’
r.send_http_header
exit(Apache::OK) if r.header_only?
print <<END

mod_ruby test

END

-t

···

On 25 Nov 2002 06:28:25 -0800, kwatch kwatch@lycos.jp wrote:

I have a trouble with using mod_ruby 1.0.1.
I got the string “Content-Type: text/html” in browser when accessed to
mod_ruby script.

I wrote a script ‘sample.rbx’:
.----------------------------------------
#!/usr/bin/ruby

print “Content-Type: text/html\n\n”

print <<END

mod_ruby test

END .----------------------------------------

I find that I don’t need the “exit(Apache::OK) if r.header_only?” stuff and it
still gives me only the headers if I send a HEAD request. Is this stuff done
automatically by cgi.rb? If so, could people be told about this please?

Tim Bates

···

On Tue, 26 Nov 2002 09:54 am, Tom Danielsen wrote:

r = Apache.request
r.content_type = ‘text/html’
r.send_http_header
exit(Apache::OK) if r.header_only?
print <<END

mod_ruby test

END


tim@bates.id.au

tom@pogostick.net (Tom Danielsen) wrote in message news:slrnau5c1u.pbe.tom@pogostick.net

http://www.rubydoc.org/books/modruby/modruby.pdf , chapter 5

Oh, great!
I understand that I must print HTTP header when using ‘pure’ mod_ruby.

r = Apache.request
r.content_type = ‘text/html’
r.send_http_header
exit(Apache::OK) if r.header_only?
print <<END

mod_ruby test

END

Should I use Apache.request?
On my experiment, printing “HTTP/1.1 200 OK\n” seemes to be working.
…----------------------------------------
#!/usr/bin/ruby

print “HTTP/1.1 200 OK\n” # is it right?
print “Content-Type: text/html\n\n”

print <<END

mod_ruby test

END ..----------------------------------------

regards,
kwatch

r = Apache.request
r.content_type = ‘text/html’
r.send_http_header
exit(Apache::OK) if r.header_only?
print <<END

mod_ruby test

END

I find that I don’t need the “exit(Apache::OK) if r.header_only?” stuff and it
still gives me only the headers if I send a HEAD request. Is this stuff done

This is how it’s supposed to be - read up on HTTP.

automatically by cgi.rb? If so, could people be told about this please?

From apache via mod_ruby, cgi.rb is not used (is this example).

-t

···

On Tue, 26 Nov 2002 08:59:46 +0900, Tim Bates tim@bates.id.au wrote:

On Tue, 26 Nov 2002 09:54 am, Tom Danielsen wrote:

I know this. I was querying whether it is cgi.rb that does this for me, since
I don’t seem to need to do the “exit(Apache::OK) if r.header_only?” stuff.

Tim Bates

···

On Tue, 26 Nov 2002 08:16 pm, Tom Danielsen wrote:

I find that I don’t need the “exit(Apache::OK) if r.header_only?” stuff
and it still gives me only the headers if I send a HEAD request. Is this
stuff done

This is how it’s supposed to be - read up on HTTP.


tim@bates.id.au

Ok, didn’t mean to be rude! :slight_smile:

  1. cgi.rb is not used, so it must be some part of mod_ruby that does the
    magic (I have not checked).

  2. I did some testing: output is discarded after a
    Apache.request.send_http_header for HEAD requests, but the rest of
    the script is run. This may or may not be important to you…

regards, Tom

···

On Tue, 26 Nov 2002 18:52:47 +0900, Tim Bates tim@bates.id.au wrote:

I know this. I was querying whether it is cgi.rb that does this for me, since
I don’t seem to need to do the “exit(Apache::OK) if r.header_only?” stuff.

Okay, thanks. I think that is the behaviour I was hoping for, since my scripts
do some init stuff before sending the headers that need to be cleaned up. Not
that I’m expecting to get many HEAD requests, but anyway…

Oh, that leads me to another question. Does mod_ruby call functions passed to
at_exit when it finishes a script, since the interpreter doesn’t actually
exit?

Tim Bates

···

On Wed, 27 Nov 2002 09:38 am, Tom Danielsen wrote:

  1. I did some testing: output is discarded after a
    Apache.request.send_http_header for HEAD requests, but the rest of
    the script is run. This may or may not be important to you…


tim@bates.id.au