Commit | Line | Data |
---|---|---|
49ccd711 FT |
1 | package jagi.scgi; |
2 | ||
3 | import jagi.*; | |
4 | import java.util.*; | |
5 | import java.io.*; | |
6 | import java.nio.*; | |
7 | import java.nio.channels.*; | |
8 | import java.nio.charset.*; | |
9 | ||
10 | public class Jagi { | |
11 | public static void decodehead(Map<? super String, ? super String> into, Map<ByteBuffer, ByteBuffer> head, Charset coding) throws CharacterCodingException { | |
12 | for(Map.Entry<ByteBuffer, ByteBuffer> h : head.entrySet()) | |
13 | into.put(coding.newDecoder().decode(h.getKey()).toString(), coding.decode(h.getValue()).toString()); | |
14 | } | |
15 | ||
965619c0 | 16 | public static Map<Object, Object> mkenv(Map<ByteBuffer, ByteBuffer> rawhead, ReadableByteChannel input) throws IOException { |
49ccd711 FT |
17 | Map<Object, Object> env; |
18 | try { | |
19 | env = new HashMap<>(); | |
20 | decodehead(env, rawhead, Utils.UTF8); | |
21 | env.put("jagi.uri_encoding", "utf-8"); | |
22 | } catch(CharacterCodingException e) { | |
23 | env = new HashMap<>(); | |
24 | decodehead(env, rawhead, Utils.LATIN1); | |
25 | env.put("jagi.uri_encoding", "latin-1"); | |
26 | } | |
27 | env.put("jagi.version.major", 1); | |
28 | env.put("jagi.version.minor", 0); | |
29 | if(env.containsKey("HTTP_X_ASH_PROTOCOL")) | |
30 | env.put("jagi.url_scheme", env.get("HTTP_X_ASH_PROTOCOL")); | |
31 | else if(env.containsKey("HTTPS")) | |
32 | env.put("jagi.url_scheme", "https"); | |
33 | else | |
34 | env.put("jagi.url_scheme", "http"); | |
965619c0 | 35 | env.put("jagi.input", input); |
49ccd711 FT |
36 | env.put("jagi.errors", System.err); |
37 | env.put("jagi.multithread", true); | |
38 | env.put("jagi.multiprocess", false); | |
39 | env.put("jagi.run_once", false); | |
40 | env.put("jagi.cleanup", new HashSet<>()); | |
41 | return(env); | |
42 | } | |
965619c0 FT |
43 | |
44 | public static Map<Object, Object> mkenv(ReadableByteChannel sk) throws IOException { | |
45 | return(mkenv(Scgi.readhead(sk), sk)); | |
46 | } | |
49ccd711 | 47 | } |