7 import java.nio.channels.*;
8 import java.nio.charset.*;
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());
16 public static Map<Object, Object> mkenv(Map<ByteBuffer, ByteBuffer> rawhead, ReadableByteChannel input) throws IOException {
17 Map<Object, Object> env;
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");
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");
34 env.put("jagi.url_scheme", "http");
35 env.put("jagi.input", input);
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<>());
44 public static Map<Object, Object> mkenv(ReadableByteChannel sk) throws IOException {
45 return(mkenv(Scgi.readhead(sk), sk));