Skip to content
Snippets Groups Projects
Select Git revision
  • 53dfc92e142ee48709b1d796739a30a57f62baf4
  • master default
  • wip-add-ed25519
  • disable-sha1
  • lsh-2.0.4
  • experimental-20050201
  • lsh-1.4.2
  • lsh-1.2
  • lsh_2.1_release_20130626
  • converted-master-branch-to-git
  • nettle_2.4_release_20110903
  • nettle_2.3_release_20110902
  • nettle_2.2_release_20110711
  • nettle_2.1_release_20100725
  • camellia_32bit_20100720
  • nettle_2.0_release_20090608
  • converted-lsh-2.0.4-branch-to-git
  • lsh_2.0.4_release_20070905
  • lsh_2.9_exp_release_20070404
  • nettle_1.15_release_20061128
  • after_experimental_merge_20060516
  • branch_before_experimental_merge_20060516
  • converted-experimental-branch-to-git
  • head_before_experimental_merge_20060516
  • lsh_2.0.3_release_20060509
  • lsh_2.0.2_release_20060127
  • nettle_1.14_release_20051205
  • nettle_1.13_release_20051006
28 results

exception.h

Blame
  • module.pmod 2.15 KiB
    #pike __REAL_VERSION__
    
    // FIXME! doc bad
    
    //! module Protocols
    //! submodule HTTP
    //! class HeaderParser
    //!	Fast HTTP header parser. 
    
    //! module Protocols
    //! submodule HTTP
    //! method string http_decode_string(string what)
    
    constant HeaderParser=_Roxen.HeaderParser;
    constant http_decode_string=_Roxen.http_decode_string;
    
    //! method mapping(string:string|array(string)) http_decode_urlencoded_query(string query,void|mapping dest)
    //!	Decodes an URL-encoded query into a mapping.
    
    mapping(string:string|array(string))
       http_decode_urlencoded_query(string query,
    				void|mapping dest)
    {
       if (!dest) dest=([]);
    
       foreach (query/"&",string s)
       {
          string i,v;
          if (sscanf(s,"%s=%s",i,v)<2) v=i=http_decode_string(s);
          else i=http_decode_string(replace(i,"+"," ")),v=http_decode_string(replace(v,"+"," "));
          if (dest[i]) 
    	 if (arrayp(dest[i])) dest[i]+=({v});
    	 else dest[i]=({dest[i],v});
          else dest[i]=v;
       }
       
       return dest;
    }
    
    
    //! method string filename_to_type(string filename)
    //! method string extension_to_type(string extension)
    //!	Looks up the file extension in a table to return
    //!	a suitable MIME type. The table is located in the
    //!	[...]pike/lib/modules/Protocols.pmod/HTTP.pmod/Server.pmod/extensions.txt
    //!	file.
    
    mapping extensions=0;
    
    string extension_to_type(string extension)
    {
       if (!extensions)
       {
          Stdio.File f=Stdio.FILE(
    	 combine_path(__FILE__,"..","extensions.txt"),"r");
    
          mapping res=([]);
    
          while (array a=f->ngets(1000))
    	 foreach (a,string l)
    	    if (sscanf(l,"%*[ \t]%[^ \t]%*[ \t]%[^ \t]",
    		       string ext,string type)==4 &&
    		ext!="" && ext[0]!='#')
    	       res[ext]=type;
    
          extensions=res;
       }
    
       return extensions[extension] || "application/octet-stream";
    }
    
    string filename_to_type(string filename)
    {
       array v=filename/".";
       if (sizeof(v)<2) return extension_to_type("default");
       return extension_to_type(v[-1]);
    }
    
    //! method string http_date(int time)
    //!	Makes a time notification suitable for the HTTP protocol.
    
    string http_date(int time)
    {
       return Calendar.ISO_UTC.Second(time)->format_http();
    }
    
    
    // server id prefab
    
    constant http_serverid=version()+": HTTP Server module";