Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If you are bored one day, make the output like FFF with 2 files: headers and body. #86

Open
gprime31 opened this issue Mar 18, 2024 · 2 comments

Comments

@gprime31
Copy link

gprime31 commented Mar 18, 2024

If you are bored one day, make the output like FFF with 2 files: headers and body. so much easier to parse that way.

@gprime31 gprime31 changed the title If you are bored on day, make the output like FFF with 2 files: headers and body. If you are bored one day, make the output like FFF with 2 files: headers and body. Mar 18, 2024
@gprime31
Copy link
Author

gprime31 commented Mar 19, 2024

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

@gprime31
Copy link
Author

gprime31 commented Mar 19, 2024

made a fork for those like me who can't code :P
https://github.com/gprime31/meg-with-fff-output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant