@@ -332,7 +332,7 @@ public void post(String regex, HttpServerRequestCallback callback) {
332
332
}
333
333
334
334
public static android .util .Pair <Integer , InputStream > getAssetStream (final Context context , String asset ) {
335
- AssetManager am = context .getAssets ();
335
+ AssetManager am = context .getResources (). getAssets ();
336
336
try {
337
337
InputStream is = am .open (asset );
338
338
return new android .util .Pair <Integer , InputStream >(is .available (), is );
@@ -373,12 +373,16 @@ public static String tryGetContentType(String path) {
373
373
return null ;
374
374
}
375
375
376
+ private String replacePrefix (Matcher m ) {
377
+ return m .group (0 ).substring (m .end (1 ));
378
+ }
379
+
376
380
public void directory (Context context , String regex , final String assetPath ) {
377
381
final Context _context = context .getApplicationContext ();
378
382
addAction (AsyncHttpGet .METHOD , regex , new HttpServerRequestCallback () {
379
383
@ Override
380
384
public void onRequest (AsyncHttpServerRequest request , final AsyncHttpServerResponse response ) {
381
- String path = request .getMatcher (). replaceAll ( "" );
385
+ String path = replacePrefix ( request .getMatcher ());
382
386
android .util .Pair <Integer , InputStream > pair = getAssetStream (_context , assetPath + path );
383
387
final InputStream is = pair .second ;
384
388
response .getHeaders ().getHeaders ().set ("Content-Length" , String .valueOf (pair .first ));
@@ -401,7 +405,7 @@ public void onCompleted(Exception ex) {
401
405
addAction (AsyncHttpHead .METHOD , regex , new HttpServerRequestCallback () {
402
406
@ Override
403
407
public void onRequest (AsyncHttpServerRequest request , final AsyncHttpServerResponse response ) {
404
- String path = request .getMatcher (). replaceAll ( "" );
408
+ String path = replacePrefix ( request .getMatcher ());
405
409
android .util .Pair <Integer , InputStream > pair = getAssetStream (_context , assetPath + path );
406
410
final InputStream is = pair .second ;
407
411
StreamUtility .closeQuietly (is );
@@ -428,7 +432,7 @@ public void directory(String regex, final File directory, final boolean list) {
428
432
addAction ("GET" , regex , new HttpServerRequestCallback () {
429
433
@ Override
430
434
public void onRequest (AsyncHttpServerRequest request , final AsyncHttpServerResponse response ) {
431
- String path = request .getMatcher (). replaceAll ( "" );
435
+ String path = replacePrefix ( request .getMatcher ());
432
436
File file = new File (directory , path );
433
437
434
438
if (file .isDirectory () && list ) {
0 commit comments