haproxy-charset.html 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <!DOCTYPE html>
  2. <html lang="en-us">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="generator" content="Hugo 0.88.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 class="twitter">
  23. <a href="http://twitter.com/pleasantprog">@pleasantprog</a>
  24. </li>
  25. <li><a href="/pages/projects.html">projects</a></li>
  26. <li><a href="/posts.html">archives</a></li>
  27. <li><a href="/tags.html">tags</a></li>
  28. <li><a href="/rss.xml">rss</a></li>
  29. </ul>
  30. </nav>
  31. </header>
  32. <div id="container">
  33. <main id="content" role="main">
  34. <article itemscope itemtype="http://schema.org/BlogPosting">
  35. <h1 class="p-name entry-title" itemprop="headline name">
  36. <a href="/posts/haproxy-charset.html">Haproxy Charset</a></h1>
  37. <small>
  38. <span class="dateline">Posted: <time itemprop="datePublished" datetime="2016-06-24">2016-06-24</time></span>
  39. | More posts about
  40. <a class="tag p-category" href="/tags/sysadmin.html" rel="tag">
  41. sysadmin
  42. </a>
  43. <a class="tag p-category" href="/tags/haproxy.html" rel="tag">
  44. haproxy
  45. </a>
  46. </small>
  47. <div class="e-content entry-content" itemprop="entry-text">
  48. <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>
  49. <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>
  50. <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>
  51. <p>After a bit of experimenting, I had success with this:</p>
  52. <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
  53. acl has_charset hdr_sub(content-type) -i charset=
  54. rspirep (Content-Type.*) \1;\ charset=utf-8 unless has_charset
  55. </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>
  56. </div>
  57. <aside class="postpromonav">
  58. <nav>
  59. <ul class="pager clearfix">
  60. <li class="previous">
  61. <a href="/posts/cloudflare-shenanigans.html" rel="prev" title="Cloudflare Shenanigans">&larr; Previous post</a>
  62. </li>
  63. <li class="next">
  64. <a href="/posts/openpreppad.html" rel="next" title="OpenPrepPad">Next post &rarr;</a>
  65. </li>
  66. </ul>
  67. </nav>
  68. </aside>
  69. <section class="comments">
  70. <script
  71. data-isso="https://isso.pleasantprogrammer.com/"
  72. data-isso-require-author="true"
  73. data-isso-vote="false"
  74. src="https://isso.pleasantprogrammer.com/js/embed.min.js">
  75. </script>
  76. <section id="isso-thread"></section>
  77. </section>
  78. </article>
  79. </main>
  80. <footer id="footer" role="contentinfo">
  81. <p>
  82. <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/deed.en_US">
  83. <img alt="CC-BY-SA" style="border-width:0" src="https://licensebuttons.net/l/by-sa/3.0/80x15.png">
  84. </a> &copy; 2020 Thomas Dy - Powered by <a href="http://gohugo.io">Hugo</a></p>
  85. </footer>
  86. </div>
  87. <script src="/assets/js/konami.js"></script>
  88. <script>
  89. var easter_egg = new Konami();
  90. easter_egg.code = function() {
  91. var el = document.getElementById('thomas');
  92. if(el.className == "whoa") {
  93. el.className = "";
  94. }
  95. else {
  96. el.className = "whoa";
  97. }
  98. document.body.scrollTop = document.documentElement.scrollTop = 0;
  99. }
  100. easter_egg.load();
  101. </script>
  102. </body>
  103. </html>