]> granicus.if.org Git - transmission/commitdiff
#1129 alternate fix: / should redirect to, not replace, /transmission/web
authorCharles Kerr <charles@transmissionbt.com>
Wed, 6 Aug 2008 00:24:05 +0000 (00:24 +0000)
committerCharles Kerr <charles@transmissionbt.com>
Wed, 6 Aug 2008 00:24:05 +0000 (00:24 +0000)
libtransmission/rpc-server.c

index bc3f75339a94403dd017d9635af14759281687eb..b744958b3c48292c16be09c302b6abe8a6d5d135 100644 (file)
@@ -236,6 +236,24 @@ handle_upload( struct shttpd_arg * arg )
     }
 }
 
+static void
+handle_root( struct shttpd_arg * arg )
+{
+    const char * redirect = "HTTP/1.1 200 OK""\r\n"
+                            "Content-Type: text/html" "\r\n"
+                            "\r\n"
+                            "<html><head>" "\r\n"
+                            "  <meta http-equiv=\"Refresh\" content=\"2; url=/transmission/web\">" "\r\n"
+                            "</head><body>" "\r\n"
+                            "  <p>redirecting to <a href=\"/transmission/web\">/transmission/web</a></p>" "\r\n"
+                            "</body></html>" "\r\n";
+    const size_t n = strlen( redirect );
+    memcpy( arg->out.buf, redirect, n );
+    arg->in.num_bytes = arg->in.len;
+    arg->out.num_bytes = n;
+    arg->flags |= SHTTPD_END_OF_OUTPUT;
+}
+
 static void
 handle_rpc( struct shttpd_arg * arg )
 {
@@ -365,8 +383,10 @@ startServer( tr_rpc_server * server )
         if( clutchDir && *clutchDir )
         {
             tr_inf( _( "Serving the web interface files from \"%s\"" ), clutchDir );
-            argv[argc++] = tr_strdup( "-root" );
-            argv[argc++] = tr_strdup( clutchDir );
+            argv[argc++] = tr_strdup( "-aliases" );
+            argv[argc++] = tr_strdup_printf( "%s=%s,%s=%s",
+                                             "/transmission/clutch", clutchDir,
+                                             "/transmission/web", clutchDir );
         }
 
         argv[argc] = NULL; /* shttpd_init() wants it null-terminated */
@@ -374,6 +394,7 @@ startServer( tr_rpc_server * server )
         server->ctx = shttpd_init( argc, argv );
         shttpd_register_uri( server->ctx, "/transmission/rpc", handle_rpc, server );
         shttpd_register_uri( server->ctx, "/transmission/upload", handle_upload, server );
+        shttpd_register_uri( server->ctx, "/", handle_root, server );
 
         evtimer_set( &server->timer, rpcPulse, server );
         evtimer_add( &server->timer, &tv );