Code Monkey home page Code Monkey logo

Comments (2)

godfat avatar godfat commented on August 12, 2024

I think this is introduced by: ac00e89
We could revert it (but need to make sure the original problem is still fixed), or fix this is by
enforcing the RESPONSE_BODY always be UTF-8 encoded, as something like this:
(not tested)

class EnforceEncoding
  def initialize; app; @app = app; end
  def call env, &k
    @app.call(env) do |res|
      res[RC::RESPONSE_BODY].force_encoding('UTF-8')
      k.call(res)
    end
  end
end

and use it before JsonResponse:

MatchingApiClient = RC::Builder.client do
  use RC::DefaultSite , ENVIRONMENTS[:producton]
  use RC::DefaultQuery, { threshold: 0 } 
  use RC::JsonRequest, true
  use RC::JsonResponse, true
  use EnforceEncoding
  use RC::CommonLogger, method(:puts)
  use RC::Cache       , nil, 3600
end

However, this means we're ignoring any encoding other than UTF-8,
I am not sure if this is ok for you? Dealing with any possible encoding
is hard :( For example, if the encoding is not ASCII-7bit compatible,
then parsing JSON might fail anyway, and so on so forth.

I am thinking that, maybe we shouldn't make sure everything is
UTF-8 encoded, but make sure everything is ASCII-8bit encoded.
This is also ignoring encoding, but at least we're not giving
possibly improperly encoded UTF-8 strings.

Thoughts?

from rest-core.

godfat avatar godfat commented on August 12, 2024

This is reverted in 6c16cb8. Please let me know if this is happening again. Thanks!

from rest-core.

Related Issues (18)

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.