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

Revert "fix headers/body order (#55)" #74

Merged
merged 1 commit into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions formatter/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ type HeaderCleaner struct {
// Post is inserted after the request headers.
Post *bytes.Buffer

HeadersDone chan<- struct{}

buf []byte
line []byte
}
Expand All @@ -31,8 +29,6 @@ func (c *HeaderCleaner) Write(p []byte) (n int, err error) {
n = len(p)
cp := c.buf
p = bytes.Replace(p, capath, ccapath, 1) // Fix curl misformatted line

closeAfterWrite := false
for len(p) > 0 {
idx := bytes.IndexByte(p, '\n')
if idx == -1 {
Expand All @@ -52,9 +48,6 @@ func (c *HeaderCleaner) Write(p []byte) (n int, err error) {
}
case '<':
c.line = c.line[i+2:]
if bytes.Equal(c.line, []byte("\r\n")) && c.HeadersDone != nil {
closeAfterWrite = true
}
case '}', '{':
ignore = true
if c.Verbose && c.Post != nil {
Expand All @@ -69,13 +62,9 @@ func (c *HeaderCleaner) Write(p []byte) (n int, err error) {
if !ignore {
cp = append(cp, c.line...)
}

c.line = c.line[:0]
}
_, err = c.Out.Write(cp)
if closeAfterWrite {
close(c.HeadersDone)
}
return
}

Expand Down
26 changes: 1 addition & 25 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,28 +138,14 @@ func main() {
fmt.Println()
return
}

cmd := exec.Command("curl", opts...)
cmd.Stdin = stdin
cmd.Stdout = stdout

tmpOut := &formatter.HeaderCleaner{
cmd.Stderr = &formatter.HeaderCleaner{
Out: stderr,
Verbose: verbose,
Post: input,
}

if terminal.IsTerminal(stdoutFd) && terminal.IsTerminal(stderrFd) && !quiet {
headerBlock := make(chan struct{})
cmd.Stdout = &blockedWrite{
ch: headerBlock,
out: stdout,
}
tmpOut.HeadersDone = headerBlock
}

cmd.Stderr = tmpOut

if (opts.Has("I") || opts.Has("head")) && terminal.IsTerminal(stdoutFd) {
cmd.Stdout = ioutil.Discard
}
Expand Down Expand Up @@ -189,13 +175,3 @@ func headerSupplied(opts args.Opts, header string) bool {
}
return false
}

type blockedWrite struct {
ch <-chan struct{}
out io.Writer
}

func (c *blockedWrite) Write(p []byte) (n int, err error) {
<-c.ch
return c.out.Write(p)
}