func ServeTestHTTP(conn *http.Conn, req *http.Request) { req.Close = true if api_key, ok := req.Header["Authorization"]; !ok || api_key != API_KEY { text := []byte(ERROR_CODES[http.StatusUnauthorized]) conn.SetHeader("Content-Type", "text/html;charset=ISO-8859-1") conn.SetHeader("Cache-Control", "must-revalidate,no-cache,no-store") conn.SetHeader("Content-Length", strconv.Itoa(len(text))) conn.WriteHeader(http.StatusUnauthorized) conn.Write(text) conn.Flush() return } if text, ok := URL_MAPPINGS[req.URL.Path]; ok { conn.SetHeader("Content-Type", "application/xml;charset=UTF-8") conn.SetHeader("Transfer-Encoding", "chunked") // for some reason, api.rapleaf.com does not send Content-Length // when sending stored data conn.WriteHeader(http.StatusOK) conn.Write([]byte(text)) conn.Flush() return } text := []byte(ERROR_CODES[http.StatusNotFound]) conn.SetHeader("Content-Type", "text/html;charset=ISO-8859-1") conn.SetHeader("Cache-Control", "must-revalidate,no-cache,no-store") conn.SetHeader("Content-Length", strconv.Itoa(len(text))) conn.WriteHeader(http.StatusNotFound) conn.Write(text) conn.Flush() return }