Open gprime31 opened 5 months ago
func (r response) save(pathPrefix string, noHeaders bool) (string, error) {
var headersContent, bodyContent []byte
// Convert headers slice to a single byte slice
if !noHeaders {
for _, header := range r.headers {
headersContent = append(headersContent, header...)
headersContent = append(headersContent, '\n')
}
}
// Body content is already in the correct format
bodyContent = r.body
// Generate checksum for uniqueness
checksum := sha1.Sum(append(headersContent, bodyContent...))
parts := []string{pathPrefix, r.request.Hostname(), fmt.Sprintf("%x", checksum)}
basePath := path.Join(parts...)
// Create directory if it doesn't exist
if _, err := os.Stat(path.Dir(basePath)); os.IsNotExist(err) {
if err := os.MkdirAll(path.Dir(basePath), 0750); err != nil {
return basePath, err
}
}
// Save headers to a separate file if they exist
headersPath := basePath + ".headers"
if !noHeaders {
if err := ioutil.WriteFile(headersPath, headersContent, 0640); err != nil {
return headersPath, err
}
}
// Save body to its file
bodyPath := basePath + ".body"
if err := ioutil.WriteFile(bodyPath, bodyContent, 0640); err != nil {
return bodyPath, err
}
return basePath, nil
}
here is the fix for anyone else that wants it. Credit: https://x.com/YouGina
made a fork for those like me who can't code :P https://github.com/gprime31/meg-with-fff-output
If you are bored one day, make the output like FFF with 2 files: headers and body. so much easier to parse that way.