Giter Club home page Giter Club logo

Comments (7)

cllns avatar cllns commented on June 20, 2024

Hi there and welcome! I'm glad you're experiencing the joy of Hanami :)

I can look into this more on Monday but, in the meantime, this PR might be helpful: hanami/controller#396

Keep us updated, we may need to update the docs to reflect some nuanced behavior.

from hanami.

dviana19 avatar dviana19 commented on June 20, 2024

@cllns thanks for the link, it really helped me to find the issue.

So basically, this is the line triggering 406 status that I'm getting.

Looking into the PR you provided it seems that there was a accept method that it should be used along with adding a new format, like this:

  class CustomFromAccept < Hanami::Action
    config.format custom: "application/custom"

    accept :json, :custom

    def handle(*, res)

But I get an undefined_method error when trying to use accept(maybe it was removed?). So when it reaches the enforce_accept method, it tries to match the basic accept headers text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8 with the new custom mime type, but it doesn't match because custom doesn't match with any of the basic accept headers.

I think that if in the accept headers there is */* it should be automatically accepted, right? You don't need to check since this means that any mime type is acceptable. This aceppted_mime_type? should be smarth enough to match */* with anything. Or make the accept work again?

from hanami.

dviana19 avatar dviana19 commented on June 20, 2024

Another finding from this PR - the accepted_formats config was removed

from hanami.

cllns avatar cllns commented on June 20, 2024

@dviana19 I was able to successfully use a format :turbo_stream in an example Hanami 2.1 action, after setting that same config.

Check it out here and let me know if you still have any issues: https://github.com/cllns/example-app-format-turbo-stream

from hanami.

dviana19 avatar dviana19 commented on June 20, 2024

hey @cllns, thank you for replying. However, I cloned your repo and I still get the same error. I'm using docker, but I don't know if it's influencing the outcome here.

I get the 406 just by adding the following piece of code.

module Bookshelf
  class App < Hanami::App
    config.actions.formats.add :turbo_stream, "text/vnd.turbo-stream.html"
  end
end

This is a request to /home action, which I removed the format :turbo_stream from it and only left the piece of code above.
Captura de Tela 2024-05-29 às 22 56 00

from hanami.

dviana19 avatar dviana19 commented on June 20, 2024

I've tried one fix: adding the turbo stream to the default types here. But I don't know if you want to go in that direction.

from hanami.

cllns avatar cllns commented on June 20, 2024

When you clone my repo and run rake test, do both examples pass? They should. I have a test for the MIME type header. If there's some other issue then can you illustrate it with a failing test and share it? (preferably based on my example repo, either here or as a PR there)

from hanami.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.