Merge pull request #23 from gardenofconcepts/master

Bugfix: Printing is not working via socket adapter
This commit is contained in:
Fabian Weber 2021-05-06 09:22:16 +02:00 committed by GitHub
commit d81e49e956
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 2 deletions

View File

@ -51,7 +51,18 @@ func (h *SocketAdapter) SendRequest(url string, r *Request, additionalData io.Wr
return nil, fmt.Errorf("unable to encode IPP request: %v", err)
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(payload))
var body io.Reader
size := len(payload)
if r.File != nil && r.FileSize != -1 {
size += r.FileSize
body = io.MultiReader(bytes.NewBuffer(payload), r.File)
} else {
body = bytes.NewBuffer(payload)
}
req, err := http.NewRequest("POST", url, body)
if err != nil {
return nil, fmt.Errorf("unable to create HTTP request: %v", err)
}
@ -67,7 +78,7 @@ func (h *SocketAdapter) SendRequest(url string, r *Request, additionalData io.Wr
return nil, err
}
req.Header.Set("Content-Length", strconv.Itoa(len(payload)))
req.Header.Set("Content-Length", strconv.Itoa(size))
req.Header.Set("Content-Type", ContentTypeIPP)
req.Header.Set("Authorization", fmt.Sprintf("Local %s", cert))