Skip to content

Latest commit

 

History

History
46 lines (35 loc) · 1.02 KB

README.md

File metadata and controls

46 lines (35 loc) · 1.02 KB

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.