Agent-TCLI-Package-Net
view release on metacpan or search on metacpan
lib/Agent/TCLI/Package/Net/HTTPD.pm view on Meta::CPAN
type: Param
---
Agent::TCLI::Parameter:
name: regex
constraints:
- ASCII
help: A regular expression pattern
manual: >
The regex should be a string that can be evaluated inside a regular
expression. It should not include the delimeters or be provided in
qr() form.
type: Param
---
Agent::TCLI::Parameter:
name: logging
help: Turn on logging to the Tail command line queue
manual: >
The logging switch turns on logging to the line queue monitored by the
Tail command. This does not write to logs disk. One may then set up
Tail tests for specific URI's to determine exactly which ones got through.
To turn off, use no_logging.
By default the line queue will only hold 10 lines so memory cannot
accidentally be exhausted.
type: Switch
---
Agent::TCLI::Parameter:
name: response
aliases: resp
constraints:
- ASCII
-
- IN_ARRAY
- OK200
- NA404
- BeGone
default: OK200
help: The desired response
manual: >
The response must be one of the pre-defined responses. Currently these are:
OK200, NA404, BeGone.
The default is OK200.
type: Param
---
Agent::TCLI::Parameter:
name: handlers
help: Show the active handlers
manual: >
The handlers are stored in a format compatible with PoCo::Server::SimpleHTTP.
The DIR is the regex and the EVENT is the response.
type: Switch
---
Agent::TCLI::Parameter:
name: ports
help: Show the active HTTPD ports
manual: >
This will show the active httpd ports.
type: Switch
---
Agent::TCLI::Command:
name: httpd
call_style: session
command: tcli_httpd
contexts:
ROOT: httpd
handler: establish_context
help: simple http web server
manual: >
httpd provides a simple web server that can respond to and log requests.
By default it responds with a Status code 404 to all requests. One may add
a select few other status code responses using regular expression pattern
matching if desired. One cannot change content, only status codes.
Httpd is useful for network testing situations where the response codes
are being monitored by the network.
topic: net
usage: httpd spawn port=8080
---
Agent::TCLI::Command:
name: spawn
call_style: session
command: tcli_httpd
contexts:
httpd: spawn
handler: spawn
help: starts an http server on a particular port
manual: >
The spawn command starts an httpd listener on a particular port. One
may enable more than one httpd listener so long as they are
using different ports.
The script must have root priviledges if the port is less than 1024.
parameters:
port:
address:
hostname:
required:
port:
topic: net
usage: httpd spawn port=8080
---
Agent::TCLI::Command:
name: stop
call_style: session
command: tcli_httpd
contexts:
httpd: stop
handler: stop
help: Stops a running http server on a particular port
manual: >
The stop command stops an httpd listener running on the specified port. It
will return an error if the port cannot be found in the list of servers
running.
parameters:
port:
required:
port:
topic: net
usage: httpd stop port=8080
---
Agent::TCLI::Command:
name: uri
call_style: session
command: tcli_httpd
contexts:
httpd: uri
handler: establish_context
help: adds or removes a uri regex from the httpd
manual: >
The httpd can be set to respond to different uri queries with this command.
topic: net
usage: httpd uri add regex=^/good/.* response=OK200
---
Agent::TCLI::Command:
name: uri_add
call_style: session
command: tcli_httpd
contexts:
httpd:
uri: add
handler: uri
help: adds a uri regex from the httpd
manual: >
Adds a uri regular expression and the desired response to the handler table.
Regular expressions are applied in order of their entry into the table and
the first match is the one that wins. One cannot delete the default
catch-all response, but one can add a different catch-all response in
front of it using regex=.*
One cannot add uri's while a HTTPD server is running. The Agent will crash.
parameters:
regex:
response:
required:
regex:
topic: net
usage: httpd uri add regex=^/good/.* response=OK200
---
Agent::TCLI::Command:
name: uri_delete
call_style: session
command: tcli_httpd
contexts:
httpd:
uri: delete
handler: uri
help: removes a uri regex from the httpd
manual: >
This command removes an existing regex from the uri handler list.
It must match exactly to the existing uri regex that was added. It
does not allow removal of the default NA404 response.
parameters:
regex:
required:
regex:
topic: net
usage: httpd uri add regex=^/good/.* response=OK200
---
Agent::TCLI::Command:
name: set
call_style: session
command: tcli_httpd
contexts:
httpd: set
handler: settings
help: adjust default settings
parameters:
logging:
address:
port:
hostname:
regex:
response:
topic: net
usage: httpd set hostname=example.com
---
Agent::TCLI::Command:
name: show
call_style: session
command: tcli_httpd
contexts:
httpd: show
handler: show
help: show tail default settings and state
parameters:
logging:
address:
port:
hostname:
regex:
response:
handlers:
ports:
topic: testing
usage: httpd show settings
...
}
sub _start {
my ($kernel, $self, $session) =
@_[KERNEL, OBJECT, SESSION];
$self->Verbose("_start: tcli httpd starting");
# are we up before OIO has finished initializing object?
if (!defined( $self->name ))
{
$kernel->yield('_start');
return;
}
# There is only one command object per TCLI
$kernel->alias_set($self->name);
$self->handlers( [
{
'DIR' => '.*',
'SESSION' => $self->name,
'EVENT' => 'NA404',
},
] ) unless defined($self->handlers);
$self->Verbose("_start Dump ".$self->dump(1),3);
}
sub _shutdown :Cumulative {
my ($kernel, $self, $session) =
@_[KERNEL, OBJECT, SESSION];
$self->Verbose($self->name.':_shutdown:');
foreach my $port ( keys %{ $self->ports } )
{
$self->Verbose("_shutdown: $port");
$kernel->post( 'HTTPD'.$port , 'SHUTDOWN' );
}
return ('_shutdown '.$self->name )
}
( run in 0.566 second using v1.01-cache-2.11-cpan-437f7b0c052 )