Merge: Nitcorn improvements & avoid double Tnits
authorJean Privat <jean@pryen.org>
Wed, 10 Sep 2014 22:30:00 +0000 (18:30 -0400)
committerJean Privat <jean@pryen.org>
Wed, 10 Sep 2014 22:30:00 +0000 (18:30 -0400)
The tnitter part was asked by @privat

Pull-Request: #740
Reviewed-by: Jean Privat <jean@pryen.org>

contrib/tnitter/src/action.nit
lib/nitcorn/file_server.nit
lib/nitcorn/media_types.nit
lib/nitcorn/reactor.nit
lib/nitcorn/server_config.nit

index db3847f..d054b49 100644 (file)
@@ -136,6 +136,11 @@ class Tnitter
                                # Post a Tnit!
                                var text = request.post_args["text"]
                                db.post(user, text)
+
+                               # Redirect the user to avoid double posting
+                               var response = new HttpResponse(303)
+                               response.header["Location"] = request.uri
+                               return response
                        end
                end
 
index e3471a3..3dadab9 100644 (file)
@@ -128,7 +128,9 @@ class FileServer
                                        var ext = local_file.file_extension
                                        if ext != null then
                                                var media_type = media_types[ext]
-                                               if media_type != null then response.header["Content-Type"] = media_type
+                                               if media_type != null then
+                                                       response.header["Content-Type"] = media_type
+                                               else response.header["Content-Type"] = "application/octet-stream"
                                        end
 
                                        file.close
index bf5d74a..e16798e 100644 (file)
@@ -95,6 +95,7 @@ class MediaTypes
                types["asx"]        = "video/x-ms-asf"
                types["asf"]        = "video/x-ms-asf"
                types["mng"]        = "video/x-mng"
+               types["apk"]        = "application/vnd.android.package-archive"
        end
 end
 
index a8f9236..0457f3c 100644 (file)
@@ -61,6 +61,9 @@ class HttpServer
                        end label
                end
 
+               # Use default virtual host if none already responded
+               if virtual_host == null then virtual_host = factory.config.default_virtual_host
+
                # Get a response from the virtual host
                var response
                if virtual_host != null then
index 2decb16..f90d4ef 100644 (file)
@@ -21,10 +21,11 @@ module server_config
 
 # Server instance configuration
 class ServerConfig
-       # Virtual hosts list
+       # `VirtualHost`s served by this server
        var virtual_hosts = new VirtualHosts(self)
 
-       # TODO implement serialization or something like that
+       # Default `VirtualHost` to respond to requests not handled by any of the `virtual_hosts`
+       var default_virtual_host: nullable VirtualHost = null
 end
 
 # A `VirtualHost` configuration