You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Claude Warren <cl...@xenei.com> on 2021/02/15 16:36:46 UTC

[users@httpd] result codes from Bash CGI

Greetings,

I am playing with Bash based CGI.  It works reasonably well.  I know that
it is not blindingly fast, but I think it will be sufficient for what I
want to do if I can solve one problem.  I can see how to generate any
result code other than 200.

Is there a way to set the result code to anything else?  If so how?  Is
there documentation?

Thank you,
Claude

-- 
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren

Re: [users@httpd] result codes from Bash CGI

Posted by Antony Stone <An...@apache.open.source.it>.
On Monday 15 February 2021 at 17:36:46, Claude Warren wrote:

> Greetings,
> 
> I am playing with Bash based CGI.

Maybe if you give us an example of exactly how you are doing this, it would 
help us to answer your question:

> I can see how to generate any result code other than 200.

I assume a "not" is missing from that sentence :)

> Is there a way to set the result code to anything else?  If so how?  Is
> there documentation?

There are plenty of examples of CGI scripts return other status codes, 
although I've no idea how many might be written in bash.

My guess is that you might need to set the exit code of your script to 
something specific, but as I say, show us what you're doing so far and we might 
have a better idea.


Antony.

-- 
Late in 1972 President Richard Nixon announced that the rate of increase of 
inflation was decreasing.   This was the first time a sitting president used a 
third derivative to advance his case for re-election.

 - Hugo Rossi, Notices of the American Mathematical Society

                                                   Please reply to the list;
                                                         please *don't* CC me.

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


Re: [users@httpd] result codes from Bash CGI

Posted by Claude Warren <cl...@xenei.com>.
Doh!  PBKAS!  I originally coded with the wrong header.  Thanks for the
clarification and patience.

Claude

On Thu, Feb 18, 2021 at 10:18 PM Dino Ciuffetti <di...@tuxweb.it> wrote:

> I see that they are easy to use and understand, but I could not find any
> reference to them in the documentation. The fact that Bash can be used as a
> CGI language is in the documentation, but nothing on the helper functions
> -- not even that they exist.
>
>
> May be you'll not find how to write something in Bash or a CGI script to
> the apache httpd manual. There are no helper functions.
> I'll try with this one, even simpler, only with the use of the "printf"
> bash shell builtin command and some comments.
> HTH
>
> https://gist.github.com/dam2k/de1e5a4335f21cca57e8cae980009778
>
>

-- 
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren

Re: [users@httpd] result codes from Bash CGI

Posted by Dino Ciuffetti <di...@tuxweb.it>.
I see that they are easy to use and understand, but I could not find any reference to them in the documentation. The fact that Bash can be used as a CGI language is in the documentation, but nothing on the helper functions -- not even that they exist.

May be you'll not find how to write something in Bash or a CGI script to the apache httpd manual. There are no helper functions.
I'll try with this one, even simpler, only with the use of the "printf" bash shell builtin command and some comments.
HTH

https://gist.github.com/dam2k/de1e5a4335f21cca57e8cae980009778 (https://gist.github.com/dam2k/de1e5a4335f21cca57e8cae980009778)

Re: [users@httpd] result codes from Bash CGI

Posted by Claude Warren <cl...@xenei.com>.
I see that they are easy to use and understand, but I could not find any
reference to them in the documentation.  The fact that Bash can be used as
a CGI language is in the documentation, but nothing on the helper functions
-- not even that they exist.

Claude

On Thu, Feb 18, 2021 at 6:05 PM Dino Ciuffetti <di...@tuxweb.it> wrote:

> Is there documentation for any of these methods? If you can point me to
> the proper section of the code base I can probably figure it out and
> document if necessary.
> Claude
>
>
> The code is super simple, does not require any dependency and is auto
> explicative.
> You are not calling any method.
> There are 4 functions that are implemented at the beginning of the script: sendcontentheader()
> and sendstatuscode() send only a single header to stdout, endheaders() send
> newline character to end the response headers and begin the body section,
> sendbody() write some html to stdout.
>
> The function that sends the HTTP Status code header is sendstatuscode().
>
> Also, try to directly exec the script from command line to get the
> output, that is:
>
> dino@a1:/tmp# chmod 755 test.cgi
> dino@a1:/tmp# ./test.cgi
> Content-Type: text/html
> Status: 410 Gone
>
> <html>
> <head><title>HI!</title></head><body><h2>Hi there, this is <b>test.cgi</b>
> speaking.<h2><h3>HTTP Status code: 410 Gone</h3</body>
> </html>
>
>
>
>

-- 
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren

Re: [users@httpd] result codes from Bash CGI

Posted by Dino Ciuffetti <di...@tuxweb.it>.
Is there documentation for any of these methods? If you can point me to the proper section of the code base I can probably figure it out and document if necessary.

Claude
The code is super simple, does not require any dependency and is auto explicative.
You are not calling any method.
There are 4 functions that are implemented at the beginning of the script: sendcontentheader() and sendstatuscode() send only a single header to stdout, endheaders() send newline character to end the response headers and begin the body section, sendbody() write some html to stdout.

The function that sends the HTTP Status code header is sendstatuscode().

Also, try to directly exec the script from command line to get the output, that is:

dino@a1:/tmp# chmod 755 test.cgi
dino@a1:/tmp# ./test.cgi
Content-Type: text/html
Status: 410 Gone

<html>
<head><title>HI!</title></head><body><h2>Hi there, this is <b>test.cgi</b> speaking.<h2><h3>HTTP Status code: 410 Gone</h3</body>
</html>

Re: [users@httpd] result codes from Bash CGI

Posted by Claude Warren <cl...@xenei.com>.
Is there documentation for any of these methods?  If you can point me to
the proper section of the code base I can probably figure it out and
document if necessary.

Claude

On Mon, Feb 15, 2021 at 11:59 PM Dino Ciuffetti <di...@tuxweb.it> wrote:

> So I would do something like
> echo "Status: 410 Gone"
> to create a "410 Gone" result code and message?
> Claude
>
> Yes. You got the point.
> Please check this CGI bash script I made for you as an example:
> https://gist.github.com/dam2k/5df0d8d3fdabc41e8ce2c799734f65d4
>


-- 
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren

Re: [users@httpd] result codes from Bash CGI

Posted by Dino Ciuffetti <di...@tuxweb.it>.
So I would do something like

echo "Status: 410 Gone"

to create a "410 Gone" result code and message?

Claude

Yes. You got the point.
Please check this CGI bash script I made for you as an example: https://gist.github.com/dam2k/5df0d8d3fdabc41e8ce2c799734f65d4 (https://gist.github.com/dam2k/5df0d8d3fdabc41e8ce2c799734f65d4)

Re: [users@httpd] result codes from Bash CGI

Posted by Claude Warren <cl...@xenei.com>.
So I would do something like

echo "Status: 410 Gone"

to create a "410 Gone" result code and message?

Claude

On Mon, Feb 15, 2021 at 6:37 PM Eric Covener <co...@gmail.com> wrote:

> There is a pseudo header you can emit from your CGI called Status that
> allows you to change the HTTP status code.
> You can set it just like you'd set e.g. Content-Type
>
> On Mon, Feb 15, 2021 at 11:37 AM Claude Warren <cl...@xenei.com> wrote:
> >
> > Greetings,
> >
> > I am playing with Bash based CGI.  It works reasonably well.  I know
> that it is not blindingly fast, but I think it will be sufficient for what
> I want to do if I can solve one problem.  I can see how to generate any
> result code other than 200.
> >
> > Is there a way to set the result code to anything else?  If so how?  Is
> there documentation?
> >
> > Thank you,
> > Claude
> >
> > --
> > I like: Like Like - The likeliest place on the web
> > LinkedIn: http://www.linkedin.com/in/claudewarren
>
>
>
> --
> Eric Covener
> covener@gmail.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>

-- 
I like: Like Like - The likeliest place on the web
<http://like-like.xenei.com>
LinkedIn: http://www.linkedin.com/in/claudewarren

Re: [users@httpd] result codes from Bash CGI

Posted by Eric Covener <co...@gmail.com>.
There is a pseudo header you can emit from your CGI called Status that
allows you to change the HTTP status code.
You can set it just like you'd set e.g. Content-Type

On Mon, Feb 15, 2021 at 11:37 AM Claude Warren <cl...@xenei.com> wrote:
>
> Greetings,
>
> I am playing with Bash based CGI.  It works reasonably well.  I know that it is not blindingly fast, but I think it will be sufficient for what I want to do if I can solve one problem.  I can see how to generate any result code other than 200.
>
> Is there a way to set the result code to anything else?  If so how?  Is there documentation?
>
> Thank you,
> Claude
>
> --
> I like: Like Like - The likeliest place on the web
> LinkedIn: http://www.linkedin.com/in/claudewarren



-- 
Eric Covener
covener@gmail.com

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