title: How do I get Go's net/http package to stop removing double slashes?
body: <p>Consider the following very basic "net/http"-program:</p>
  
  <pre><code>package main
  
  import (
      "net/http"
      "log"
  )
  
  func entry(w http.ResponseWriter, req *http.Request) {
      log.Println(req.URL.Path)
      path := []byte(req.URL.Path)    
      w.Write(path)
  }
  
  func main() {
      http.HandleFunc("/", entry)
      err := http.ListenAndServe("localhost:10000", nil)
      if err != nil {
          log.Fatal("ListenAndServe: ", err)
      }
  }
  </code></pre>
  
  <p>When accessing the URL, <code>http://localhost:10000/a//b</code>, the <code>DefaultServerMux</code>, which is what the default <code>HandleFunc()</code> and <code>ListenAndServe()</code> uses, redirects it to <code>/a/b</code>, effectively removing the double slash.</p>
  
  <p>The <a href="https://golang.org/pkg/net/http/#ServeMux" rel="nofollow noreferrer">documentation for <code>ServerMux</code></a> does specify that it 'sanitises' URL requests:</p>
  
  <blockquote>
    <p>ServeMux also takes care of sanitizing the URL request path, redirecting any request containing . or .. elements or repeated slashes to an equivalent, cleaner URL.</p>
  </blockquote>
  
  <p>But what if I don't want it to?  I have a scenario where <code>//</code> != <code>/</code> in my URLs.  I could find another solution.  But is there a way to still use Go's "net/http" package, while it not sanitising my URLs like this?  Preferably with as little re-writing as possible.</p>
  
  <p>(I will probably find a different solution than having <code>//</code> and <code>/</code> being distinct, since I am probably happy with other features that <code>ServerMux</code> provides (in case a solution requires me to use another multiplexer), but now I am curious whether there is a solution with Go's standard "net/http" package.)</p>