Skip to content

Commit

Permalink
refactor streamReader
Browse files Browse the repository at this point in the history
  • Loading branch information
liushuangls committed Oct 10, 2023
1 parent 787e774 commit 54c904d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
6 changes: 4 additions & 2 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,15 @@ func sendRequestStream[T streamable](client *Client, req *http.Request) (*stream
if isFailureStatusCode(resp) {
return new(streamReader[T]), client.handleErrorResp(resp)
}
return &streamReader[T]{
reader := &streamReader[T]{
emptyMessagesLimit: client.config.EmptyMessagesLimit,
reader: bufio.NewReader(resp.Body),
response: resp,
errAccumulator: utils.NewErrorAccumulator(),
unmarshaler: &utils.JSONUnmarshaler{},
}, nil
}
reader.SetHeader(resp.Header)
return reader, nil
}

func (c *Client) setCommonHeaders(req *http.Request) {
Expand Down
10 changes: 2 additions & 8 deletions stream_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ type streamReader[T streamable] struct {
response *http.Response
errAccumulator utils.ErrorAccumulator
unmarshaler utils.Unmarshaler

httpHeader
}

func (stream *streamReader[T]) Recv() (response T, err error) {
Expand Down Expand Up @@ -109,11 +111,3 @@ func (stream *streamReader[T]) unmarshalError() (errResp *ErrorResponse) {
func (stream *streamReader[T]) Close() {
stream.response.Body.Close()
}

func (stream *streamReader[T]) Header() http.Header {
return stream.response.Header
}

func (stream *streamReader[T]) GetRateLimitHeaders() RateLimitHeaders {
return NewRateLimitHeaders(stream.Header())
}

0 comments on commit 54c904d

Please sign in to comment.