Signed-off-by: Miloslav Trmač <mitr@redhat.com>
This commit is contained in:
Miloslav Trmač
2024-05-09 21:49:41 +02:00
parent dcf937e170
commit 7649059a0d
474 changed files with 30496 additions and 30923 deletions

View File

@@ -16,6 +16,8 @@ package runtime
import (
"bufio"
"context"
"errors"
"io"
"net/http"
"strings"
@@ -96,10 +98,16 @@ func (p *peekingReader) Read(d []byte) (int, error) {
if p == nil {
return 0, io.EOF
}
if p.underlying == nil {
return 0, io.ErrUnexpectedEOF
}
return p.underlying.Read(d)
}
func (p *peekingReader) Close() error {
if p.underlying == nil {
return errors.New("reader already closed")
}
p.underlying = nil
if p.orig != nil {
return p.orig.Close()
@@ -107,9 +115,11 @@ func (p *peekingReader) Close() error {
return nil
}
// JSONRequest creates a new http request with json headers set
// JSONRequest creates a new http request with json headers set.
//
// It uses context.Background.
func JSONRequest(method, urlStr string, body io.Reader) (*http.Request, error) {
req, err := http.NewRequest(method, urlStr, body)
req, err := http.NewRequestWithContext(context.Background(), method, urlStr, body)
if err != nil {
return nil, err
}