Skip to content
Simple and light CGI library for D
D
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
source
.gitignore Initial commit Feb 14, 2020
LICENSE
README.md
dub.sdl

README.md

dcgi

Simple and light CGI library for D. Documentation

Basic example

import dcgi;

mixin DCGI; // Needed for boilerplate code

void cgi(Request req, Output output) 
{
  output("Hello, world");
}

Full example

/+ dub.sdl:
name "Hello_dcgi"
description "A minimal dcgi application."
dependency "dcgi" version="~>0.1.0"
+/

import dcgi;

mixin DCGI!my_cgi_function; // Custom function

@DisplayExceptions // Show exceptions directly on output
@MaxRequestBodyLength(1024) // Limit request body to 1kb
void my_cgi_function(Request request, Output output) 
{
  output.status = 201; // Default is 200
  output.addHeader("content-type", "text/plain"); // Default is text/html
  output("Hello, world");
  
  if ("REQUEST_URI" in request.header)
    output("Uri:", request.header["REQUEST_URI"]);
}

Notes

  • stdout is redirected to stderr.
  • a simple cgiLog function is included for debug purpouses.
  • tested on linux only.
You can’t perform that action at this time.