Skip to content

Resource-mapper now considers content type when inserting index.html - #1260

Closed
jaxoncreed wants to merge 1 commit into
masterfrom
fix/#1171
Closed

Resource-mapper now considers content type when inserting index.html#1260
jaxoncreed wants to merge 1 commit into
masterfrom
fix/#1171

Conversation

@jaxoncreed

@jaxoncreed jaxoncreed commented Jul 11, 2019

Copy link
Copy Markdown
Contributor

Fix for #1120 again

@jaxoncreed
jaxoncreed requested a review from RubenVerborgh July 11, 2019 18:51
@RubenVerborgh

Copy link
Copy Markdown
Contributor

How does this address #1171?

@jaxoncreed

Copy link
Copy Markdown
Contributor Author

Oops mislabeled it. It's #1120

@RubenVerborgh RubenVerborgh left a comment

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.

While this might hide the behavior of #1120, I don't think this is the proper fix, as it extends ResourceMapper with a piece of logic that seems out of place there.

Comment thread lib/resource-mapper.js
match = files.find(f => this._removeDollarExtension(f) === filename)
// Check if the index file exists
} else if (files.includes(this._indexFilename)) {
} else if (files.includes(this._indexFilename) && contentType && contentType.includes(this._indexContentType)) {

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.

Hmm. First of all, this can't be correct; the last condition will be true with text/htmlxyz whereas we probably want it to fail. So why the choice for includes here? Is contentType expected to be an Accept header? That would not be a correct use of the parameter, which is intended for a single content type. (Namely in the case of a PUT, where the client sends a Content-Type.)

However, I don't understand the intuition behind this line. What is is supposed to mean? The index file can only be served if the user agent "sends" a content type, that just so happens to be the content type of the index file?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Perhaps it is, because the contentType can have more values than „text/html” (IIRC a charset parameter or something). That's why an accept match isn't possible.
I had a „starts with” comparison in one of my projects, but a check against MIME types?
https://www.npmjs.com/package/@goa/content-type came after a short search for „RFC 7231”.

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.

I'd be surprised if a GET could be reduced to a single content type (it cannot), but indeed, content types can have arguments.

Comment thread lib/ldp.js
let path, contentType, stats
try {
({ path, contentType } = await this.resourceMapper.mapUrlToFile({ url: options, searchIndex }))
({ path, contentType } = await this.resourceMapper.mapUrlToFile({ url: options, contentType: options.contentType, searchIndex }))

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.

(See comment below first.)

Is options.contentType the value of the Accept header? Then it's not a content type, so can't be passed. But in any case, passing the content type to the resource mapper is only meaningful in the case of PUT or POST, when a new URL needs to be created; the mapper does not do content negotiation.

It seems to me that the desired logic should be implemented at this level, perhaps as follows:

  • Set searchIndex to false if the Accept header does not explicitly ask for text/html.
  • Then call mapUrlToFile.

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.

Ah okay thanks. I'll do that

@jaxoncreed

Copy link
Copy Markdown
Contributor Author

Turns out this is much more complicated than setting https://github.com/solid/node-solid-server/blob/master/lib/handlers/get.js#L48 to

ret = await ldp.get(options, req.accepts('html'))

searchIndex is not only used to return HTML files, but is also used to translate /profile/card into /profile/card$.ttl. So there will probably need to be another flag for "return HTML" or something.

I will come back to this one later.

@RubenVerborgh

Copy link
Copy Markdown
Contributor

searchIndex is not only used to return HTML files

We should probably document what exactly it does 🙂
I thought its purpose was to return the index.html when present; if switched off, it will only allow exact path matches.

but is also used to translate /profile/card into /profile/card$.ttl

That is independent of searchIndex.

So there will probably need to be another flag for "return HTML" or something.

We should avoid that; ResourceMapper is content-type-agnostic at the moment.

@jaxoncreed

Copy link
Copy Markdown
Contributor Author

but is also used to translate /profile/card into /profile/card$.ttl

I might be interpreting this incorrectly, but I believe that https://github.com/solid/node-solid-server/blob/master/lib/resource-mapper.js#L119 says that in order to find files with the $ extension, search index must be true.

Is this the way it should work?

@jaxoncreed

Copy link
Copy Markdown
Contributor Author

I'm closing this PR in favour of the one proposed here #1282

@jaxoncreed jaxoncreed closed this Aug 26, 2019
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.

3 participants