Ranides Atterwim il y a 10 ans
Parent
commit
a87655469e

+ 5 - 2
assira/src/main/java/net/ranides/assira/io/uri/impl/CHttpHandler.java

@@ -176,9 +176,12 @@ public class CHttpHandler extends CHandler {
         return c;
     }
     
-    private static Charset getContentCharset(String type) {
+    private static Charset getContentCharset(String type) throws IOException {
         if(null == type) {
-            return Charsets.UTF8;
+            throw new IOException("Unknown MIME type");
+        }
+        if(!type.startsWith("text/")) {
+            throw new IOException("Unsupported MIME type: " + type);
         }
         Matcher hit = RE_CHARSET.matcher(type);
         if(!hit.find()) {

+ 13 - 11
assira/src/test/java/net/ranides/assira/io/uri/impl/CHttpHandlerTest.java

@@ -86,18 +86,20 @@ public class CHttpHandlerTest {
     
     @Test
     public void testBinary() throws IOException, URISyntaxException {   
-        URIResolver r = new URIResolver().register(CHttpHandler.THAT);
-        URIHandle h4 = r.resolve("http://maven.ranides.net/net/ranides/assira/0.58/assira-0.58.jar.sha1");
+        URI uri = new URI("http://maven.ranides.net/net/ranides/assira/0.58/assira-0.58.jar.sha1");
+        URIHandle handle = CHttpHandler.THAT.resolve(uri);
         
-        System.out.printf("uri     = %s%n", h4.uri());        
-        System.out.printf("charset = %s%n", h4.charset());
-        System.out.printf("exists  = %s%n", h4.exists());
-        System.out.printf("flags   = %s%n", h4.flags());
-        System.out.printf("stream  = %s%n", IOStrings.read(h4.istream(10, 15), h4.charset()));
-        System.out.printf("reader  = %s%n", IOStrings.read(h4.reader()).length());
-        System.out.printf("time    = %s%n", h4.time(URITime.MODIFIED));
-        System.out.printf("size    = %s%n", h4.size());
-        System.out.printf("%n");
+        assertEquals(uri, handle.uri());
+        assertThrows(IOException.class, ()->{
+            handle.charset();
+        });
+        assertThrows(IOException.class, ()->{
+            handle.reader();
+        });
+        assertEquals(true, handle.exists());
+        assertEquals(URIFlags.constant(READABLE, EXISTS, FILE, BINARY, SIZE, SEEK), handle.flags());
+        assertEquals(Instant.parse("2013-03-08T01:58:30Z"), handle.time(URITime.MODIFIED));
+        assertEquals(40, handle.size());
         
     }