Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support non-English content #33

Closed
2efPer opened this issue May 14, 2020 · 2 comments · Fixed by com-lihaoyi/geny#25
Closed

support non-English content #33

2efPer opened this issue May 14, 2020 · 2 comments · Fixed by com-lihaoyi/geny#25

Comments

@2efPer
Copy link

2efPer commented May 14, 2020

  @cask.get("/")
  def getNonEnglishContent1() = "조선글"

  @cask.get("/test1")
  def getNonEnglishContent2() = "سىناك"

  @cask.get("/test2")
  def getNonEnglishContent3() = "שלום"

Browser content of non-English character changes to a garbled message.

@2efPer
Copy link
Author

2efPer commented May 15, 2020

I find two ways to solve this problem for now.
pass a HttpServerExchange parameter,

  @cask.get("/test1")
  def test1(exchange: HttpServerExchange) = {
    exchange.getResponseHeaders.put(new HttpString("Content-Type"),"text/plain; charset=utf-8")
    "سىناك"
  }

or implement a new cask.get annotation.

  class myGet(val path: String, override val subpath: Boolean = false) extends WebEndpoint{
    val methods = Seq("get")
    override def wrapFunction(ctx: Request, delegate: Delegate): Result[Raw] = {
      ctx.exchange.getResponseHeaders.put(new HttpString("Content-Type"),"text/plain; charset=utf-8")
      super.wrapFunction(ctx, delegate)
    }
  }

I think this function should be supported natively by cask.

@jodersky
Copy link
Member

It looks like this can be traced back to geny's StringWritable, which is responsible for serializing strings and setting content-type headers. Since the serializer actually uses utf-8, it would make sense to add that to the content headers too. I think the change would be minimal, probably only this line.

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 a pull request may close this issue.

2 participants