swarm icon indicating copy to clipboard operation
swarm copied to clipboard

http server returns inconsistent results for requests with trailing segment in url

Open significance opened this issue 5 years ago • 2 comments

System information

Swarm version: Swarm Version: 0.5.4-stable Go Version: go1.13.3 OS: darwin OS & Version: OSX

Expected behaviour

Where 'default-path' is set to be index.html http://localhost:8500/bzz:/a123.../something should consistently return index.html so that Single Page Apps may use in browser routers eg. react-router.

Actual behaviour

If the trailing segment of the url matches any other entries in the manifest, these are returned instead.

Steps to reproduce the behaviour

sig :: Code/df/swarmtest2222 » tree .
.
├── assets
│   └── test.css
└── index.html

1 directory, 2 files
sig :: Code/df/swarmtest2222 » swarm --defaultpath index.html --recursive up .
2a05a416579d58484f7a1afb51e83c2a11b370bfc4baf1e85e8a0ebacd85286b
sig :: Code/df/swarmtest2222 » curl localhost:8500/bzz:/2a05a416579d58484f7a1afb51e83c2a11b370bfc4baf1e85e8a0ebacd85286b/
<!DOCTYPE html>
<html>
<head>
  <title>test</title>
</head>
<body>

</body>
sig :: Code/df/swarmtest2222 » curl localhost:8500/bzz:/2a05a416579d58484f7a1afb51e83c2a11b370bfc4baf1e85e8a0ebacd85286b/b
<!DOCTYPE html>
<html>
<head>
  <title>test</title>
</head>
<body>

</body>
sig :: Code/df/swarmtest2222 » curl localhost:8500/bzz:/2a05a416579d58484f7a1afb51e83c2a11b370bfc4baf1e85e8a0ebacd85286b/a
//test
sig :: Code/df/swarmtest2222 » cat assets/test.css
//test

significance avatar Jan 08 '20 14:01 significance

this is due to the automagical feature of undermatching manifest entries. i have repeatedly asked to remove this voodoo. @zelig maybe now we're finally convinced that returning an unsolicited asset is not the right thing to do?

acud avatar Jan 20 '20 08:01 acud

Dug into this a bit more yesterday with @jmozah yesterday and thought would be worth more giving a bit more info.

We are using React Router to manage the URL using javascript in the Fairdrop app.

The usual paradigm here is that the server that is providing the html assets is configured to always serve up index.html) except in the case that it fully matches a file that exists - eg. favicon.ico, in which case that is returned. I guess this is so that Single Page Apps could easily be hosted on existing web servers.

It works well to use Swarm's --default-path flag to mimic this functionality, except in the case that the initial path matches a subset of an manifest entry.

As a result https://fairdrop.xyz/zahoor works for our Freedrop honest dropbox but e.g. https://fairdrop.xyz/zahoor does not because it's returning the favicon.ico file.

significance avatar Jan 22 '20 10:01 significance