---
name: "NetSDS::App::FCGI"
section: "3pm"
platform: "linux"
package: "libnetsds-perl"
version: "1.301-4"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/NetSDS::App::FCGI"
---

# NetSDS::App::FCGI(3pm)

FastCGI applications superclass

## NAME

NetSDS::App::FCGI - FastCGI applications superclass

## SYNOPSIS

```
        # Run application
        MyFCGI->run();
        1;
        # Application package itself
        package MyFCGI;
        use base 'NetSDS::App::FCGI';
        sub process {
                my ($self) = @_;
                $self->data('Hello World');
                $self->mime('text/plain');
                $self->charset('utf-8');
        }
```

## DESCRIPTION

`"NetSDS::App::FCGI"` module contains superclass for FastCGI applications. This class is based on `"NetSDS::App"` module and inherits all its functionality like logging, configuration processing, etc.

## CLASS API

- **new(%params)** - class constructor

  Normally constructor of application framework shouldn't be invoked directly.

- **cgi()** - accessor to CGI.pm request handler

  ```
          my $https_header = $self->cgi->https('X-Some-Header');
  ```

- **status(\[$new\_status\])** - set response HTTP status

  Paramters: new status to set

  Returns: response status value

  ```
          $self->status('200 OK');
  ```

- **mime()** - set response MIME type

  Paramters: new MIME type for response

  ```
          $self->mime('text/xml'); # output will be XML data
  ```

- **charset()** - set response character set if necessary

  ```
          $self->mime('text/plain');
          $self->charset('koi8-r'); # ouput as KOI8-R text
  ```

- **data($new\_data)** - set response data

  Paramters: new data "as is"

  ```
          $self->mime('text/plain');
          $self->data('Hello world!');
  ```

- **redirect($redirect\_url)** - send HTTP redirect

  Paramters: new URL (relative or absolute)

  This method send reponse with 302 status and new location.

  ```
          if (havent_data()) {
                  $self->redirect('http://www.google.com'); # to google!
          };
  ```

- **cookie()** -

  Paramters:

  Returns:

  This method provides.....

- **headers($headers\_hashref)** - set/get response HTTP headers

  Paramters: new headers as hash reference

  ```
          $self->headers({
                  'X-Beer' => 'Guiness',
          );
  ```

- **main\_loop()** - main FastCGI loop

  Paramters: none

  This method implements common FastCGI (or CGI) loop.

- **set\_cookie(%params)** - set cookie

  Paramters: hash (name, value, expires)

  ```
          $self->set_cookie(name => 'sessid', value => '343q5642653476', expires => '+1h');
  ```

- **get\_cookie(%params)** - get cookie by name

  Paramters: cookie name

  Returns cookie value by it's name

  ```
          my $sess = $self->get_cookie('sessid');
  ```

- **param($name)** - CGI request parameter

  Paramters: CGI parameter name

  Returns: CGI parameter value

  This method returns CGI parameter value by it's name.

  ```
          my $cost = $self->param('cost');
  ```

- **url\_param($name)** - CGI request parameter

  Paramters: URL parameter name

  Returns: URL parameter value

  This method works similar to **param()** method, but returns only parameters from the query string.

  ```
          my $action = $self->url_param('a');
  ```

- **http($http\_field)** - request HTTP header

  Paramters: request header name

  Returns: header value

  This method returns HTTP request header value by name.

  ```
          my $beer = $self->http('X-Beer');
  ```

- **https($https\_field)** - request HTTPS header

  This method returns HTTPS request header value by name and is almost the same as **http()** method except of it works with SSL requests.

  ```
          my $beer = $self->https('X-Beer');
  ```

- **raw\_cookie()** - get raw cookie data

  Just proxying `"raw_cookie()"` method from CGI.pm

- **user\_agent()** - User-Agent request header

  ```
          my $ua_info = $self->user_agent();
  ```

- **request\_method()** - HTTP request method

  ```
          if ($self->request_method eq 'POST') {
                  $self->log("info", "Something POST'ed from client");
          }
  ```

- **script\_name()** - CGI script name

  Returns: script name from CGI.pm

- **path\_info()** - get PATH\_INFO value

  ```
          if ($self->path_info eq '/help') {
                  $self->data('Help yourself');
          }
  ```

- **remote\_host()** - remote (client) host name

  ```
          warn "Client from: " . $self->remote_host();
  ```

- **remote\_addr()** - remote (client) IP address

  Returns: IP address of client from REMOTE\_ADDR environment

  ```
          if ($self->remote_addr eq '10.0.0.1') {
                  $self->data('Welcome people from our gateway!');
          }
  ```

- **\_set\_req\_cookies()** - fetching request cookies (internal method)

  Fetching cookies from HTTP request to object `"req_cookies"` variable.

## EXAMPLES

See `"samples"` catalog for more example code.

## SEE ALSO

CGI, CGI::Fast, NetSDS::App

## AUTHOR

Michael Bochkaryov \<misha@rattler.kiev.ua\>

## LICENSE

Copyright (C) 2008-2009 Net Style Ltd.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
