title: Go http cannot handle HTTP requests with no PATH
body: <p>I am writing a small HTTP server that receives HTTP POSTs from some embedded devices. Unfortunately these devices send malformed POST request that contain no PATH component:</p>
  
  <pre><code>POST  HTTP/1.1
  Host: 192.168.13.130:8080
  Content-Length: 572
  Connection: Keep-Alive
  
  &lt;?xml version="1.0"?&gt;
  ....REST OF XML BODY
  </code></pre>
  
  <p>Due to this the Go http never passes the request to any of my handlers and always responds with 400 Bad Request.</p>
  
  <p>Since these are embedded devices and changing the way they send the request is not an option I though maybe I could intercept the HTTP requests and if no PATH is present add one (e.g. /) to it before it passes to the SeverMux.</p>
  
  <p>I tried this by creating my own CameraMux but Go always responds with 400 Bad Request even before calling the ServeHTTP() method from my custom ServeMux (see code below).</p>
  
  <p>Is there a way to modify the Request object at some point before Go http responds Bad Request or there is a way to make Go accept the request even if it has no PATH?</p>
  
  <pre><code>package main
  
  import (
    "net/http"                            
    "log"
    "os"
  )
  
  type CameraMux struct {                 
    mux *http.ServeMux                    
  } 
  
  func (handler *CameraMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
    // Try to fix URL.Path here but the server never reaches this method.    
    log.Printf("URL %v\n", r.URL.Path)
    handler.mux.ServeHTTP(w, r)
  }
  
  func process(path string) error {
    log.Printf("Processing %v\n", path)
    // Do processing based on path and body  
    return nil
  }
  
  func main() {
  
    http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
  
      path := r.URL.Path[1:]
  
      log.Printf("Processing path %v\n", path) 
  
      err := process(path)
  
      if err != nil {
        w.WriteHeader(http.StatusBadRequest) 
      } else {
        w.WriteHeader(http.StatusOK)
      }
    })
  
    err := http.ListenAndServe(":8080", &amp;CameraMux{http.DefaultServeMux})
  
    if err != nil {
      log.Println(err)
      os.Exit(1)
    }
  
    os.Exit(0)
  }
  </code></pre>