Skip to content

Commit

Permalink
fixed eof errors in the decode methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Fabian Weber committed Mar 6, 2020
1 parent 26693ea commit 6fab588
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
8 changes: 3 additions & 5 deletions ipp-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"os"
Expand Down Expand Up @@ -114,11 +113,10 @@ func (c *IPPClient) SendRequest(url string, req *Request, additionalResponseData
}

// read the response into a temp buffer due to some wired EOF errors
httpBody, _ := ioutil.ReadAll(httpResp.Body)
// fmt.Println(httpBody)
return NewResponseDecoder(bytes.NewBuffer(httpBody)).Decode(additionalResponseData)
// httpBody, _ := ioutil.ReadAll(httpResp.Body)
// return NewResponseDecoder(bytes.NewBuffer(httpBody)).Decode(additionalResponseData)

// return NewResponseDecoder(httpResp.Body).Decode()
return NewResponseDecoder(httpResp.Body).Decode(additionalResponseData)
}

// Print one or more `Document`s using IPP `Create-Job` followed by `Send-Document` request(s).
Expand Down
5 changes: 5 additions & 0 deletions reqest.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ func (d *RequestDecoder) Decode(data io.Writer) (*Request, error) {
// decode attribute buffer
for {
if _, err := d.reader.Read(startByteSlice); err != nil {
// when we read from a stream, we may get an EOF if we want to read the end tag
// all data should be read and we can ignore the error
if err == io.EOF {
break
}
return nil, err
}

Expand Down
5 changes: 5 additions & 0 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ func (d *ResponseDecoder) Decode(data io.Writer) (*Response, error) {
// decode attribute buffer
for {
if _, err := d.reader.Read(startByteSlice); err != nil {
// when we read from a stream, we may get an EOF if we want to read the end tag
// all data should be read and we can ignore the error
if err == io.EOF {
break
}
return nil, err
}

Expand Down

0 comments on commit 6fab588

Please sign in to comment.