# GoAhead Handlers

GoAhead responds to client requests by routing the request to a request handler. The request handler is responsible for generating the response content or redirecting to another more suitable handler.

GoAhead provides a suite of standard handlers for various content types and web frameworks. The standard handlers supplied with GoAhead are:

Name | Description
--- | ---
action | Handler to serve C functions bound to URLs
continue | Pseudo handler for request rewriting
cgi | Handler to serve CGI programs
file | Handler to serve web pages, images and static resources
jst | Handler to serve Javascript templates for dynamic content
options | Handler to serve HTTP Options and Trace methods
redirect | Handler to process route redirects
upload | Handler to process file uploads

You can extend GoAhead by creating your own custom handler to process Http requests and perform any processing you desire. Once created handlers are configured via routes in the route table. See Creating Handlers in the Developer's Guide, and Request Routing for more details.

## Request Processing

When a request is received from the client, GoAhead parses the HTTP request headers and then determines the best GoAhead route for the request. A route contains the full details for how to process a request including the required handler and required authentication. GoAhead matches each route in the route table in-order and selects the first matching route. The route specifies the desired handler for requests matching that route.

The last step of selecting a route is calling the candidate handler's optional match() callback. If the match callback returns true, the handler will be selected. If it returns false, the handler and route will be skipped and the route selection process continues.

Once the route has been selected, GoAhead invokes the handler service callback to process the request and generate a response. At this point, request body data will be received and buffered. The handler may choose to not handler the request by returning a zero status code. In that case, the router continues matching routes to find a more suitable route and handler combination.

## Standard Handlers

GoAhead includes a suite of handlers that process standard content.

### Action Handler

The Action handler maps URLs to simple C functions. Handler to serve C functions bound to URLs. Here is an example route directive to configure the action handler for URLs that begin with /action.

`route uri=/action handler=action`

See GoActions for more details.

### Continue Handler

The Continue handler is a pseudo handler that performs nothing. It simply continues routing by proceeding to examine the next route in the routing table. The Continue handler is typically used when performing authentication which must be checked before proceeding to serve the request using the appropriate content handler. Here is a route directive that redirects to a login page if not authenticated. If the user is already authenticated, routing continues to examine the next route directive in the route table.

`route uri=/ auth=form handler=continue redirect=401@/login.html`

See User Authentication for more examples.

### CGI Handler

Handler to serve CGI programs See CGI Programs for more information. For example:

`route uri=/cgi-bin handler=cgi`

### File Handler

Handler to serve web pages, images and static resources. The file handler is the default handler and will be used by route directives if another handler is not specified.

### JST Handler

Handler to serve Javascript templates for dynamic content. See Javascript Templates for more information. For example:

`route uri=/ extensions=jst handler=asp,jst`

This will use the JST handler for all requests that have an asp or jst URI extension. Note: you can also create multiple routes using the same handler.

### Options Handler

Handler to serve HTTP Options and Trace methods. The HTTP OPTIONS and TRACE methods are somewhat special in that they are handled centrally by the server instead of by the corresponding content handler. For example:

`route uri=/ methods=OPTIONS|TRACE handler=options`

### Redirect Handler

Handler to process route redirects. The Redirect handler is used to redirect the client to alternate content. It is also used during login authentication to redirect the client to a login, logout or logged in page. For example:

`route uri=/ protocol=http redirect=*@https handler=redirect`

This will redirect all HTTP requests to use SSL

### Upload Handler

Handler to process file uploads. The upload handler is a special case that filters uploaded files. It is not a "terminal" handler and can be used with another handler to actually handle generating the response. The Upload handler is automatically configured and does not need to be defined in the route table.

© Embedthis Software, 2003-2015. All rights reserved.