Skip to content
Snippets Groups Projects
Select Git revision
  • 4ef8d0eec0f37a5ba50941bbd69b0aff49dc9625
  • master default protected
  • 9.0
  • 8.0
  • nt-tools
  • 7.8
  • 7.6
  • 7.4
  • 7.2
  • 7.0
  • 0.6
  • rosuav/latex-markdown-renderer
  • rxnpatch/rxnpatch
  • marcus/gobject-introspection
  • rxnpatch/8.0
  • rosuav/pre-listening-ports
  • rosuav/async-annotations
  • rosuav/pgsql-ssl
  • rxnpatch/rxnpatch-broken/2023-10-06T094250
  • grubba/fdlib
  • grubba/wip/sakura/8.0
  • v8.0.2020
  • v8.0.2018
  • v8.0.2016
  • v8.0.2014
  • v8.0.2012
  • v8.0.2008
  • v8.0.2006
  • v8.0.2004
  • v8.0.2002
  • v8.0.2000
  • v8.0.1998
  • v8.0.1996
  • v8.0.1994
  • v8.0.1992
  • v8.0.1990
  • v8.0.1988
  • v8.0.1986
  • rxnpatch/clusters/8.0/2025-04-29T124414
  • rxnpatch/2025-04-29T124414
  • v8.0.1984
41 results

module.pmod

Blame
  • module.pmod 1.82 KiB
    #pike __REAL_VERSION__
    
    //! Fast HTTP header parser.
    constant HeaderParser=_Roxen.HeaderParser;
    
    //!
    constant http_decode_string=_Roxen.http_decode_string;
    
    
    //! 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;
    }
    
    
    
    //! Looks up the file extension in a table to return a suitable MIME
    //! type.
    string extension_to_type(string extension)
    {
       return MIME.ext_to_media_type(extension) || "application/octet-stream";
    }
    
    //! Looks up the file extension in a table to return a suitable MIME
    //! type.
    string filename_to_type(string filename)
    {
       array v=filename/".";
       if (sizeof(v)<2) return extension_to_type("default");
       return extension_to_type(v[-1]);
    }
    
    //!	Makes a time notification suitable for the HTTP protocol.
    //! @param time
    //!  The time in seconds since the 00:00:00 UTC, January 1, 1970
    //! @returns
    //!  The date in the HTTP standard date format.
    //!  Example : Thu, 03 Aug 2000 05:40:39 GMT
    string http_date(int time)
    {
       return Calendar.ISO_UTC.Second(time)->format_http();
    }
    
    //! 	Decode a HTTP date to seconds since 1970 (UTC)
    //! @returns
    //!	zero (UNDEFINED) if the given string isn't a HTTP date
    int http_decode_date(string data)
    {
       Calendar.ISO_UTC.Second s=
          Calendar.ISO_UTC.parse("%e, %D %M %Y %h:%m:%s GMT",data);
       if (!s) return UNDEFINED;
       return s->unix_time();
    }