Skip to content

swarm/api: bug fix exact match for manifest#15329

Merged
karalabe merged 1 commit into
ethereum:masterfrom
holisticode:exact-match-fix
Nov 24, 2017
Merged

swarm/api: bug fix exact match for manifest#15329
karalabe merged 1 commit into
ethereum:masterfrom
holisticode:exact-match-fix

Conversation

@holisticode
Copy link
Copy Markdown
Contributor

This PR fixes a bug where a request for /styles.css would fail with status code 300 if the request resolves to a manifest and the manifest contains the exact match (empty path in sub-manifest) and more entries, for example styles.css.map

Copy link
Copy Markdown
Member

@nonsense nonsense left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good to me. I have added only one minor comment with regard to tests.

Comment thread swarm/api/manifest_test.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to test the else-condition:

else if !multiple && entry.Status == http.StatusMultipleChoices

in order to cover incorrect response status if we didn't expect multiple choices status, but got one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added! Thanks for comment

Comment thread swarm/api/manifest.go
if entry.ContentType == ManifestType {
err := self.loadSubTrie(entry, quitC)
if err == nil && entry.subtrie != nil {
subentries := entry.subtrie.entries
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

loadSubTrie() returns no error, but probably it should? The underlying errors that would bubble up would be from readManifest() Have it been evaluated whether they are relevant for this case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?
func (self *manifestTrie) loadSubTrie(entry *manifestTrieEntry, quitC chan bool) (err error) {
looks like it does return an error to me?

Copy link
Copy Markdown
Contributor

@nolash nolash Nov 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I meant the error is always nil the way it is now

Copy link
Copy Markdown
Contributor Author

@holisticode holisticode Nov 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not sure I understand:

361 func (self *manifestTrie) loadSubTrie(entry *manifestTrieEntry, quitC chan bool) (err error) {
362   if entry.subtrie == nil {
363     hash := common.Hex2Bytes(entry.Hash)
364     entry.subtrie, err = loadManifest(self.dpa, hash, quitC)
365     entry.Hash = "" // might not match, should be recalculated
366   }
367   return
368 }

if loadManifest returns an error, it would be assigned to err on line 364?

Copy link
Copy Markdown
Contributor

@nolash nolash Nov 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jeez, forget I said anything. I'm a moron. You are right, of course.

func TestExactMatch(t *testing.T) {
quitC := make(chan bool)
mf := manifest("shouldBeExactMatch.css", "shouldBeExactMatch.css.map")
trie, err := readManifest(mf, nil, nil, quitC)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the .map one?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this is exactly what caused the error we are trying to fix: if there was a file "shouldBeExactMatch.css" and a file "shouldBeExactMatch.css.map" (.map files are often generated by SASS generators for CSS and are actually used in development only, but that's how we found out: our own webpage would not load...), then if the client requested "shouldBeExactMatch.css", the result would be 300 Multiple Choices, instead of serving the file itself

@nonsense
Copy link
Copy Markdown
Member

@fjl this is approved from Swarm team. Feel free to merge when you think is appropriate.

@karalabe karalabe merged commit f0ac925 into ethereum:master Nov 24, 2017
@karalabe karalabe added this to the 1.8.0 milestone Nov 24, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants