Implement static responses for testing
This commit is contained in:
parent
db98c72b3e
commit
17a8d892bf
|
@ -2,10 +2,19 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
|
||||||
"log"
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// temporary, to provide a mock server for the HTML5 client while the actual
|
||||||
|
// storage is still under development here.
|
||||||
|
const (
|
||||||
|
exampleId = "0bc88096498be52d7909bcec815d37b3"
|
||||||
|
)
|
||||||
|
|
||||||
|
var fileRoute = regexp.MustCompile("^/files/([^/]+)$")
|
||||||
|
|
||||||
func serveHttp() error {
|
func serveHttp() error {
|
||||||
http.HandleFunc("/", route)
|
http.HandleFunc("/", route)
|
||||||
|
|
||||||
|
@ -22,6 +31,17 @@ func route(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
if r.Method == "POST" && r.URL.Path == "/files" {
|
if r.Method == "POST" && r.URL.Path == "/files" {
|
||||||
createFile(w, r)
|
createFile(w, r)
|
||||||
|
} else if match := fileRoute.FindStringSubmatch(r.URL.Path); match != nil {
|
||||||
|
switch r.Method {
|
||||||
|
case "HEAD":
|
||||||
|
w.Header().Set("X-Resume", "bytes=0-99")
|
||||||
|
case "GET":
|
||||||
|
reply(w, http.StatusNotImplemented, "File download")
|
||||||
|
case "PUT":
|
||||||
|
reply(w, http.StatusOK, "chunk created")
|
||||||
|
default:
|
||||||
|
reply(w, http.StatusMethodNotAllowed, "Invalid http method")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
reply(w, http.StatusNotFound, "No matching route")
|
reply(w, http.StatusNotFound, "No matching route")
|
||||||
}
|
}
|
||||||
|
@ -54,8 +74,6 @@ func createFile(w http.ResponseWriter, r *http.Request) {
|
||||||
contentType = "application/octet-stream"
|
contentType = "application/octet-stream"
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = contentType
|
w.Header().Set("Location", "/files/"+exampleId)
|
||||||
id := uid()
|
w.WriteHeader(http.StatusCreated)
|
||||||
|
|
||||||
w.Header().Set("Location", "/files/"+id)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue