Make it possible to specify BR format in query string #97

Open
michals wants to merge 1 commits from michals/autogits:main into main
2 changed files with 14 additions and 5 deletions

View File

@@ -275,7 +275,7 @@ func main() {
res.Write([]byte("404 page not found\n")) res.Write([]byte("404 page not found\n"))
}) })
http.HandleFunc("GET /status/{Project}", func(res http.ResponseWriter, req *http.Request) { http.HandleFunc("GET /status/{Project}", func(res http.ResponseWriter, req *http.Request) {
mime := ParseMimeHeader(req) mime := ParseMimeHeaderAndQuery(req)
obsPrj := req.PathValue("Project") obsPrj := req.PathValue("Project")
common.LogInfo(" GET /status/"+obsPrj, "["+mime.MimeType()+"]") common.LogInfo(" GET /status/"+obsPrj, "["+mime.MimeType()+"]")
@@ -296,7 +296,7 @@ func main() {
} }
}) })
http.HandleFunc("GET /status/{Project}/{Package}", func(res http.ResponseWriter, req *http.Request) { http.HandleFunc("GET /status/{Project}/{Package}", func(res http.ResponseWriter, req *http.Request) {
mime := ParseMimeHeader(req) mime := ParseMimeHeaderAndQuery(req)
obsPrj := req.PathValue("Project") obsPrj := req.PathValue("Project")
obsPkg := req.PathValue("Package") obsPkg := req.PathValue("Package")
common.LogInfo(" GET /status/"+obsPrj+"/"+obsPkg, "["+mime.MimeType()+"]") common.LogInfo(" GET /status/"+obsPrj+"/"+obsPkg, "["+mime.MimeType()+"]")
@@ -326,7 +326,7 @@ func main() {
}) })
http.HandleFunc("GET /status/{Project}/{Package}/{Repository}", func(res http.ResponseWriter, req *http.Request) { http.HandleFunc("GET /status/{Project}/{Package}/{Repository}", func(res http.ResponseWriter, req *http.Request) {
mime := ParseMimeHeader(req) mime := ParseMimeHeaderAndQuery(req)
obsPrj := req.PathValue("Project") obsPrj := req.PathValue("Project")
obsPkg := req.PathValue("Package") obsPkg := req.PathValue("Package")
repo := req.PathValue("Repository") repo := req.PathValue("Repository")
@@ -355,7 +355,7 @@ func main() {
} }
}) })
http.HandleFunc("GET /status/{Project}/{Package}/{Repository}/{Arch}", func(res http.ResponseWriter, req *http.Request) { http.HandleFunc("GET /status/{Project}/{Package}/{Repository}/{Arch}", func(res http.ResponseWriter, req *http.Request) {
mime := ParseMimeHeader(req) mime := ParseMimeHeaderAndQuery(req)
prj := req.PathValue("Project") prj := req.PathValue("Project")
pkg := req.PathValue("Package") pkg := req.PathValue("Package")
repo := req.PathValue("Repository") repo := req.PathValue("Repository")

View File

@@ -21,7 +21,16 @@ var AcceptedStatusMimes []string = []string{
XmlMime, XmlMime,
} }
func ParseMimeHeader(req *http.Request) *MimeHeader { func ParseMimeHeaderAndQuery(req *http.Request) *MimeHeader {
format := req.URL.Query().Get("format")
switch format {
case "svg":
return &MimeHeader{MimeHeader: SvgMime}
case "json":
return &MimeHeader{MimeHeader: JsonMime}
case "xml":
return &MimeHeader{MimeHeader: XmlMime}
}
proposedMimes := req.Header.Values("Accept") proposedMimes := req.Header.Values("Accept")
mime := MimeHeader{MimeHeader: SvgMime} mime := MimeHeader{MimeHeader: SvgMime}
if len(proposedMimes) == 0 { if len(proposedMimes) == 0 {