#line 379 "/home/travis/build/felix-lang/felix/src/packages/web.fdoc"
  include "web/__init__";
  
  publish """
  Use make_<response type> to wrap html in an apropriate response
  """
  
  class HTTPResponse {
    open LowResTime;
    open HTTPStatusCodes;
    open MIMEType;
    open Assoc_list;
    struct http_response {
      status_code:status_code;
      last_modified:tm;
      content_type:mime_type;
      headers:assoc_list[string,string];
      content:string;
    }
  
    typedef headers_t = assoc_list[string,string];
    fun no_headers ():headers_t => Empty[string*string];
  
    fun http_header (response:http_response) =>
  """HTTP/1.0 """ + str(response.status_code) +"""\r
  Date: """ + rfc1123_date() + """\r
  Server: felix web server\r
  Last-Modified: """ + rfc1123_date(response.last_modified) +"""\r
  Connection: close\r
  Content-Type: """ + str(response.content_type) + """\r
  Content-Length: """ + str (len response.content) + """\r
  """+(fold_left (fun(x:string) (y:string):string => x + y) "" (map (fun (n:string*string) => n.(0)+": "+n.(1)+"\r\n") response.headers))+"""\r
  """;
  
  
    fun make_image(mime:mime_type, content:string) =>
      http_header(http_response(SC_OK,localtime(#time_t),mime,#no_headers,content)) +
        content;
  
    fun make_image(mime:mime_type, content:string, headers:headers_t) =>
      http_header(http_response(SC_OK,localtime(#time_t),mime,headers,content)) +
        content;
  
    fun make_css (content:string) =>
      http_header(http_response(SC_OK,localtime(#time_t),text css,#no_headers,content)) +
        content;
  
    fun make_js (content:string) =>
      http_header(http_response(SC_OK,localtime(#time_t),application javascript,#no_headers,content)) +
        content;
  
    fun make_json (content:string) =>
      http_header(http_response(SC_OK,localtime(#time_t),application json,#no_headers,content)) +
        content;
  
    fun make_not_found (content:string) =>
      let response = http_response(SC_NOT_FOUND,localtime(#time_t),text html,#no_headers,
  				  content) in
      	http_header(response) + response.content;
  
    fun make_not_implemented (content:string) =>
      let response = http_response(SC_NOT_IMPLEMENTED,localtime(#time_t),text html,#no_headers,
  				  content) in
      	http_header(response) + response.content;
  
  
    fun make_see_other (location:string) =>
      let response = http_response(SC_SEE_OTHER,localtime(#time_t),text html,Cons(("Location",location),Empty[string^2]),"") in
      	http_header(response) + response.content;
  
    fun make_forbidden (content:string) =>
      let response = http_response(SC_FORBIDDEN,localtime(#time_t),text html,#no_headers,
  				  "Forbidden: "+content) in
      	http_header(response) + response.content;
  
    fun make_unauthorized (headers:headers_t) =>
      let response = http_response(SC_UNAUTHORIZED,localtime(#time_t),text html,headers,
  				  "") in
      	http_header(response) +"\nUnauthorized";
  
    fun make_unauthorized (headers:headers_t,content:string) =>
      let response = http_response(SC_UNAUTHORIZED,localtime(#time_t),text html,headers,
  				  "") in
      	http_header(response) +"\n"+content;
  
    fun make_continue () =>
      let response = http_response(SC_CONTINUE,localtime(#time_t),text html,#no_headers,
  				  "") in
      	http_header(response) +"\r";
  
    fun make_raw (content:string) => make_raw(content,#no_headers);
    fun make_raw (content:string,headers:headers_t) =>
      http_header(http_response(SC_OK,localtime(#time_t),application octet_DASH_stream,
                                headers,content)) + content;
  
    fun make_html (content:string) => make_html(content,#no_headers);
    fun make_html (content:string,headers:headers_t) =>
      http_header(http_response(SC_OK,localtime(#time_t),text html,
                                headers,content)) + content;
    fun make_xhtml (content:string) => make_xhtml(content,#no_headers);
    fun make_xhtml (content:string,headers:headers_t) =>
      http_header(http_response(SC_OK,localtime(#time_t),application xhtml_PLUS_xml,
                                headers,content)) + content;
  
    fun make_mime (mime:mime_type, content:string) => make_mime(mime,content, #no_headers);
    fun make_mime (mime:mime_type, content:string, headers:headers_t) =>
      http_header(http_response(SC_OK,localtime(#time_t),mime,
                                headers,content)) + content;
  
  
  }
  //WWW-Authenticate: Basic realm="WallyWorld"