@@ -22,6 +22,7 @@ import (
22
22
"encoding/json"
23
23
"fmt"
24
24
"io"
25
+ "mime"
25
26
"net/http"
26
27
"time"
27
28
@@ -42,13 +43,20 @@ func (h VulsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
42
43
result := models.ScanResult {ScannedCves : models.VulnInfos {}}
43
44
44
45
contentType := r .Header .Get ("Content-Type" )
45
- if contentType == "application/json" {
46
+ mediatype , _ , err := mime .ParseMediaType (contentType )
47
+ if err != nil {
48
+ util .Log .Error (err )
49
+ http .Error (w , err .Error (), http .StatusBadRequest )
50
+ return
51
+ }
52
+
53
+ if mediatype == "application/json" {
46
54
if err = json .NewDecoder (r .Body ).Decode (& result ); err != nil {
47
55
util .Log .Error (err )
48
56
http .Error (w , "Invalid JSON" , http .StatusBadRequest )
49
57
return
50
58
}
51
- } else if contentType == "text/plain" {
59
+ } else if mediatype == "text/plain" {
52
60
buf := new (bytes.Buffer )
53
61
io .Copy (buf , r .Body )
54
62
if result , err = scan .ViaHTTP (r .Header , buf .String ()); err != nil {
@@ -57,6 +65,7 @@ func (h VulsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
57
65
return
58
66
}
59
67
} else {
68
+ util .Log .Error (mediatype )
60
69
http .Error (w , fmt .Sprintf ("Invalid Content-Type: %s" , contentType ), http .StatusUnsupportedMediaType )
61
70
return
62
71
}
@@ -69,10 +78,13 @@ func (h VulsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
69
78
70
79
// report
71
80
reports := []report.ResultWriter {
72
- report.HTTPWriter {Writer : w },
81
+ report.HTTPResponseWriter {Writer : w },
73
82
}
74
83
if c .Conf .ToLocalFile {
75
- scannedAt := time .Now ().Truncate (1 * time .Hour )
84
+ scannedAt := result .ScannedAt
85
+ if scannedAt .IsZero () {
86
+ scannedAt = time .Now ().Truncate (1 * time .Hour )
87
+ }
76
88
dir , err := scan .EnsureResultDir (scannedAt )
77
89
if err != nil {
78
90
util .Log .Errorf ("Failed to ensure the result directory: %s" , err )
0 commit comments