hono icon indicating copy to clipboard operation
hono copied to clipboard

fix(ssg): Error when ContentType is missing

Open watany-dev opened this issue 1 year ago • 4 comments

fixes: https://github.com/honojs/hono/issues/2244

This sets the specification for the defaultContentType of SSG, which was implicitly set to text/plain until now.

However, as per the issue mentioned above, this may not be appropriate. Therefore, we have added the option defaultContentType. In normal settings, routes like c.redirect, which include no content-type, will result in an error.

If set, it will fallback to the specified value. One issue is that setting the DefaultContent-type to an arbitrary value like 'aaaa' results in an empty .html file being output. This is because the default value in determineExtension is .html, but there is room for discussion on what the specification should be regarding this issue.

Author should do the followings, if applicable

  • [x] Add tests
  • [x] Run tests
  • [x] yarn denoify to generate files for Deno

watany-dev avatar Feb 20 '24 10:02 watany-dev

@yusukebe @usualoma I would like to get your opinion on this specification.

watany-dev avatar Feb 20 '24 10:02 watany-dev

I made it, but if we are going to solve the .html completion problem, it might not be much different from not providing a defaultContentType option and automatically making it an error.

watany-dev avatar Feb 20 '24 10:02 watany-dev

Hi @watany-dev. Thank you!

I can't think of any situation where defaultContentType would be needed. I think it would be very very rare, if any, so instead of providing a defaultContentType option, I think we would be better to encourage to use afterResponseHook() for prepareing fallback.

usualoma avatar Feb 20 '24 10:02 usualoma

Hey @watany-dev @usualoma !

I agree with @usualoma. I don't think defaultContentType is necessary. That's because he's right, the Content-Type is set in the Response in many cases.

However, as per the issue mentioned above, this may not be appropriate. Therefore, we have added the option defaultContentType. In normal settings, routes like c.redirect, which include no content-type, will result in an error.

Certainly the case for redirect responses must be considered, but it is a question of how to handle 301 and 302 status codes. We can discuss that in #2180.

yusukebe avatar Feb 20 '24 11:02 yusukebe

close.

Ref: https://github.com/honojs/hono/issues/2284

watany-dev avatar Mar 04 '24 06:03 watany-dev