func handlePost(res http.ResponseWriter, req *http.Request) { scheme := "http" if req.TLS != nil || req.Header.Get("X-Forwarded-Proto") == "https" { scheme = "https" } data, err := ioutil.ReadAll(req.Body) if err != nil { log.Println("post.error.body:", err) http.Error(res, "Error reading request body: "+err.Error(), http.StatusBadRequest) return } if err := handleStatusParam(res, req); err != nil { return } res.Header().Set("Content-Type", "text/uri-list; charset=utf-8") contentType := req.Header.Get("Content-Type") uri := urinception.CreateUri(scheme, req.Host, req.URL.Path, contentType, data) fmt.Fprintln(res, uri) }
// Create a URI returning the bytes provided func BytesUri(data []byte) string { return urinception.CreateUri(scheme, host+":"+port, "/", http.DetectContentType(data), data) }