github.com/webdestroya/awsmocker@v0.2.6/http.go (about)

     1  package awsmocker
     2  
     3  import (
     4  	"io"
     5  	"net/http"
     6  )
     7  
     8  func (m *mocker) handleHttp(w http.ResponseWriter, r *http.Request) {
     9  
    10  	_, resp := m.handleRequest(r)
    11  
    12  	origBody := resp.Body
    13  	defer origBody.Close()
    14  
    15  	w.WriteHeader(resp.StatusCode)
    16  	_, _ = io.Copy(w, resp.Body)
    17  	if err := resp.Body.Close(); err != nil {
    18  		m.Warnf("Can't close response body %v", err)
    19  	}
    20  }
    21  
    22  var handleNonProxyRequest = http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
    23  	http.Error(w, "AWSMocker is meant to be used as a proxy server. Don't send requests directly to it.", http.StatusNotImplemented)
    24  })