123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <!DOCTYPE html>
- <html lang="en-us">
- <head>
- <meta charset="utf-8">
- <meta name="generator" content="Hugo 0.92.0" />
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="/assets/css/theme.css">
- <link rel="alternate" href="/rss.xml" type="application/rss+xml" title="Pleasant Programmer">
- <script type="text/javascript" src="//use.typekit.net/iwm5axp.js"></script>
- <script type="text/javascript">try{Typekit.load();}catch(e){}</script>
- <title>Haproxy Charset - Pleasant Programmer</title>
- </head>
- <body>
- <header id="header" role="banner">
- <div id="thomas">
- <img src="/assets/img/thomas.gif" alt="DJ THOMAS IN DA HAUS">
- <img src="/assets/img/thomas.png" alt="Pleasant Programmer">
- </div>
- <h1 class="site-title"><a href="/">Pleasant Programmer</a></h1>
- <nav id="menu" role="navigation">
- <ul>
- <li><a href="/pages/projects.html">projects</a></li>
- <li><a href="/posts.html">archives</a></li>
- <li><a href="/tags.html">tags</a></li>
- <li><a href="/rss.xml">rss</a></li>
- </ul>
- </nav>
- </header>
- <div id="container">
- <main id="content" role="main">
- <article itemscope itemtype="http://schema.org/BlogPosting">
- <h1 class="p-name entry-title" itemprop="headline name">
- <a href="/posts/haproxy-charset.html">Haproxy Charset</a></h1>
- <small>
- <span class="dateline">Posted: <time itemprop="datePublished" datetime="2016-06-24">2016-06-24</time></span>
- | More posts about
-
- <a class="tag p-category" href="/tags/sysadmin.html" rel="tag">
- sysadmin
- </a>
-
- <a class="tag p-category" href="/tags/haproxy.html" rel="tag">
- haproxy
- </a>
-
- </small>
- <div class="e-content entry-content" itemprop="entry-text">
- <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’t about hash codes or anything like that.</p>
- <p>By default, we use UTF-8 for text storage and rendering. A problem is that browsers don’t assume UTF-8 as the default and you need to have either a <code><meta charset="utf-8" /></code> in the HTML or <code>Content-Type: text/html; charset=utf-8</code> in the headers. A few of our services don’t set the <code>Content-Type</code> with the <code>charset=utf-8</code> part so you’d get piñata instead of piñata.</p>
- <p>Being lazy, we usually just correct this at the reverse proxy side. It’s trivial to do in nginx. You just need to add <code>charset utf-8;</code> to your configuration and you’re good. For haproxy though, I couldn’t readily find a solution for it and had to go through the docs to see what I could do.</p>
- <p>After a bit of experimenting, I had success with this:</p>
- <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
- acl has_charset hdr_sub(content-type) -i charset=
- rspirep (Content-Type.*) \1;\ charset=utf-8 unless has_charset
- </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>
- </div>
- <aside class="postpromonav">
- <nav>
- <ul class="pager clearfix">
-
- <li class="previous">
- <a href="/posts/cloudflare-shenanigans.html" rel="prev" title="Cloudflare Shenanigans">← Previous post</a>
- </li>
-
-
- <li class="next">
- <a href="/posts/openpreppad.html" rel="next" title="OpenPrepPad">Next post →</a>
- </li>
-
- </ul>
- </nav>
- </aside>
- <section class="comments">
- <script
- data-isso="https://isso.pleasantprogrammer.com/"
- data-isso-require-author="true"
- data-isso-vote="false"
- src="https://isso.pleasantprogrammer.com/js/embed.min.js">
- </script>
- <section id="isso-thread"></section>
- </section>
- </article>
- </main>
- <footer id="footer" role="contentinfo">
- <p>
- <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/deed.en_US">
- <img alt="CC-BY-SA" style="border-width:0" src="https://licensebuttons.net/l/by-sa/3.0/80x15.png">
- </a> © 2022 Thomas Dy - Powered by <a href="http://gohugo.io">Hugo</a></p>
- </footer>
- </div>
- <script src="/assets/js/konami.js"></script>
- <script>
- var easter_egg = new Konami();
- easter_egg.code = function() {
- var el = document.getElementById('thomas');
- if(el.className == "whoa") {
- el.className = "";
- }
- else {
- el.className = "whoa";
- }
- document.body.scrollTop = document.documentElement.scrollTop = 0;
- }
- easter_egg.load();
- </script>
- </body>
- </html>
|