spacecookie-0.2.0.1: gopher server daemon

Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Network.Gopher

Contents

Description

Overview

This is the main module of the spacecookie library. It allows to write gopher applications by taking care of handling gopher requests while leaving the application logic to a user-supplied function.

For a small tutorial an example of a trivial pure gopher application:

import Network.Gopher
import Network.Gopher.Util

main = do
  runGopherPure (GopherConfig "localhost" 7000 Nothing) (\req -> FileResponse (uEncode req))

This server just returns the request string as a file.

There are three possibilities for a GopherResponse:

If you use runGopher, it is the same story like in the example above, but you can do IO effects. To see a more elaborate example, have a look at the server code in this package.

Synopsis

Main API

runGopher :: GopherConfig -> (String -> IO GopherResponse) -> IO () Source #

Run a gopher application that may cause effects in IO. The application function is given the gopher request (path) and required to produce a GopherResponse.

runGopherPure :: GopherConfig -> (String -> GopherResponse) -> IO () Source #

Run a gopher application that may not cause effects in IO.

data GopherConfig Source #

necessary information to handle gopher requests

Constructors

GopherConfig 

Fields

Helper Functions

gophermapToDirectoryResponse :: Gophermap -> GopherResponse Source #

Convert a gophermap to a gopher menu response.

Representations

Responses

data GopherResponse Source #

Constructors

MenuResponse [GopherMenuItem]

gopher menu, wrapper around a list of GopherMenuItems

FileResponse ByteString

return the given ByteString as a file

ErrorResponse String

gopher menu containing a single error with the given String as text

data GopherMenuItem Source #

entry in a gopher menu

Constructors

Item GopherFileType ByteString FilePath (Maybe ByteString) (Maybe Integer)

file type, menu text, filepath (does not need to be a real file), server name (optional), port (optional)

data GopherFileType Source #

rfc-defined gopher file types plus info line and HTML

Constructors

File

text file, default type

Directory

a gopher menu

PhoneBookServer 
Error

error entry in menu

BinHexMacintoshFile 
DOSArchive 
UnixUuencodedFile 
IndexSearchServer 
TelnetSession 
BinaryFile

binary file

RedundantServer 
Tn3270Session 
GifFile

gif

ImageFile

image of any format

InfoLine

menu entry without associated file

Html

Special type for HTML, most commonly used for links to other protocols

Gophermaps

data GophermapEntry Source #

A gophermap entry makes all values of a gopher menu item optional except for file type and description. When converting to a GopherMenuItem, appropriate default values are used.

Constructors

GophermapEntry GopherFileType ByteString (Maybe FilePath) (Maybe ByteString) (Maybe Integer)

file type, description, path, server name, port number