haproxy-charset.html 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <!DOCTYPE html>
  2. <html lang="en-us">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="generator" content="Hugo 0.92.0" />
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <link rel="stylesheet" href="/assets/css/theme.css">
  8. <link rel="alternate" href="/rss.xml" type="application/rss+xml" title="Pleasant Programmer">
  9. <script type="text/javascript" src="//use.typekit.net/iwm5axp.js"></script>
  10. <script type="text/javascript">try{Typekit.load();}catch(e){}</script>
  11. <title>Haproxy Charset - Pleasant Programmer</title>
  12. </head>
  13. <body>
  14. <header id="header" role="banner">
  15. <div id="thomas">
  16. <img src="/assets/img/thomas.gif" alt="DJ THOMAS IN DA HAUS">
  17. <img src="/assets/img/thomas.png" alt="Pleasant Programmer">
  18. </div>
  19. <h1 class="site-title"><a href="/">Pleasant Programmer</a></h1>
  20. <nav id="menu" role="navigation">
  21. <ul>
  22. <li><a href="/pages/projects.html">projects</a></li>
  23. <li><a href="/posts.html">archives</a></li>
  24. <li><a href="/tags.html">tags</a></li>
  25. <li><a href="/rss.xml">rss</a></li>
  26. </ul>
  27. </nav>
  28. </header>
  29. <div id="container">
  30. <main id="content" role="main">
  31. <article itemscope itemtype="http://schema.org/BlogPosting">
  32. <h1 class="p-name entry-title" itemprop="headline name">
  33. <a href="/posts/haproxy-charset.html">Haproxy Charset</a></h1>
  34. <small>
  35. <span class="dateline">Posted: <time itemprop="datePublished" datetime="2016-06-24">2016-06-24</time></span>
  36. | More posts about
  37. <a class="tag p-category" href="/tags/sysadmin.html" rel="tag">
  38. sysadmin
  39. </a>
  40. <a class="tag p-category" href="/tags/haproxy.html" rel="tag">
  41. haproxy
  42. </a>
  43. </small>
  44. <div class="e-content entry-content" itemprop="entry-text">
  45. <p>A common problem we encounter is for things like <em>ñ</em> not showing up correctly. This actually caused <a href="http://www.rappler.com/nation/politics/elections/2016/132894-human-error-hash-election-results-code-mismatch">some issues</a> in the recent Philippine elections, but this isn&rsquo;t about hash codes or anything like that.</p>
  46. <p>By default, we use UTF-8 for text storage and rendering. A problem is that browsers don&rsquo;t assume UTF-8 as the default and you need to have either a <code>&lt;meta charset=&quot;utf-8&quot; /&gt;</code> in the HTML or <code>Content-Type: text/html; charset=utf-8</code> in the headers. A few of our services don&rsquo;t set the <code>Content-Type</code> with the <code>charset=utf-8</code> part so you&rsquo;d get piñata instead of piñata.</p>
  47. <p>Being lazy, we usually just correct this at the reverse proxy side. It&rsquo;s trivial to do in nginx. You just need to add <code>charset utf-8;</code> to your configuration and you&rsquo;re good. For haproxy though, I couldn&rsquo;t readily find a solution for it and had to go through the docs to see what I could do.</p>
  48. <p>After a bit of experimenting, I had success with this:</p>
  49. <div class="highlight"><pre tabindex="0" style="color:#e5e5e5;background-color:#000;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-text" data-lang="text"># set content-type to utf-8 if not already
  50. acl has_charset hdr_sub(content-type) -i charset=
  51. rspirep (Content-Type.*) \1;\ charset=utf-8 unless has_charset
  52. </code></pre></div><p>This is probably not the best way to do it. Arguably, we should just fix our services to have the correct <code>Content-Type</code> in the first place, but I can do that some other time.</p>
  53. </div>
  54. <aside class="postpromonav">
  55. <nav>
  56. <ul class="pager clearfix">
  57. <li class="previous">
  58. <a href="/posts/cloudflare-shenanigans.html" rel="prev" title="Cloudflare Shenanigans">&larr; Previous post</a>
  59. </li>
  60. <li class="next">
  61. <a href="/posts/openpreppad.html" rel="next" title="OpenPrepPad">Next post &rarr;</a>
  62. </li>
  63. </ul>
  64. </nav>
  65. </aside>
  66. <section class="comments">
  67. <script
  68. data-isso="https://isso.pleasantprogrammer.com/"
  69. data-isso-require-author="true"
  70. data-isso-vote="false"
  71. src="https://isso.pleasantprogrammer.com/js/embed.min.js">
  72. </script>
  73. <section id="isso-thread"></section>
  74. </section>
  75. </article>
  76. </main>
  77. <footer id="footer" role="contentinfo">
  78. <p>
  79. <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/deed.en_US">
  80. <img alt="CC-BY-SA" style="border-width:0" src="https://licensebuttons.net/l/by-sa/3.0/80x15.png">
  81. </a> &copy; 2022 Thomas Dy - Powered by <a href="http://gohugo.io">Hugo</a></p>
  82. </footer>
  83. </div>
  84. <script src="/assets/js/konami.js"></script>
  85. <script>
  86. var easter_egg = new Konami();
  87. easter_egg.code = function() {
  88. var el = document.getElementById('thomas');
  89. if(el.className == "whoa") {
  90. el.className = "";
  91. }
  92. else {
  93. el.className = "whoa";
  94. }
  95. document.body.scrollTop = document.documentElement.scrollTop = 0;
  96. }
  97. easter_egg.load();
  98. </script>
  99. </body>
  100. </html>