haproxy-charset.html 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <!DOCTYPE html>
  2. <html lang="en-us">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="generator" content="Hugo 0.18.1" />
  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="/posts.html">archives</a></li>
  26. <li><a href="/tags.html">tags</a></li>
  27. <li><a href="/rss.xml">rss</a></li>
  28. </ul>
  29. </nav>
  30. </header>
  31. <div id="container">
  32. <main id="content" role="main">
  33. <article itemscope itemtype="http://schema.org/BlogPosting">
  34. <h1 class="p-name entry-title" itemprop="headline name">
  35. <a href="/posts/haproxy-charset.html">Haproxy Charset</a></h1>
  36. <small>
  37. <span class="dateline">Posted: <time itemprop="datePublished" datetime="2016-06-24">2016-06-24</time></span>
  38. | More posts about
  39. <a class="tag p-category" href="/tags/sysadmin.html" rel="tag">
  40. sysadmin
  41. </a>
  42. <a class="tag p-category" href="/tags/haproxy.html" rel="tag">
  43. haproxy
  44. </a>
  45. </small>
  46. <div class="e-content entry-content" itemprop="entry-text">
  47. <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>
  48. <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>
  49. <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>
  50. <p>After a bit of experimenting, I had success with this:</p>
  51. <div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%"><span></span># set content-type to utf-8 if not already
  52. acl has_charset hdr_sub(content-type) -i charset=
  53. rspirep (Content-Type.*) \1;\ charset=utf-8 unless has_charset
  54. </pre></div>
  55. <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. <div id="disqus_thread"></div>
  71. <script type="text/javascript">
  72. var disqus_shortname = 'pleasantprog';
  73. var disqus_url = 'http:\/\/pleasantprogrammer.com\/posts\/haproxy-charset.html';
  74. var disqus_title = 'Haproxy Charset';
  75. var disqus_identifier = 'cache/posts/haproxy-charset.html';
  76. (function() {
  77. var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
  78. dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
  79. (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
  80. })();
  81. </script>
  82. <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
  83. <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
  84. </section>
  85. </article>
  86. </main>
  87. <footer id="footer" role="contentinfo">
  88. <p>
  89. <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/deed.en_US">
  90. <img alt="CC-BY-SA" style="border-width:0" src="http://i.creativecommons.org/l/by-sa/3.0/80x15.png">
  91. </a> &copy; 2015 Thomas Dy - Powered by <a href="http://gohugo.io">Hugo</a></p>
  92. </footer>
  93. </div>
  94. <script src="/assets/js/konami.js"></script>
  95. <script>
  96. var easter_egg = new Konami();
  97. easter_egg.code = function() {
  98. var el = document.getElementById('thomas');
  99. if(el.className == "whoa") {
  100. el.className = "";
  101. }
  102. else {
  103. el.className = "whoa";
  104. }
  105. document.body.scrollTop = document.documentElement.scrollTop = 0;
  106. }
  107. easter_egg.load();
  108. </script>
  109. </body>
  110. </html>