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

Rewind content at the end of Readable#to_s #21

Merged
merged 1 commit into from
Feb 16, 2018
Merged

Rewind content at the end of Readable#to_s #21

merged 1 commit into from
Feb 16, 2018

Conversation

janko
Copy link
Member

@janko janko commented Feb 15, 2018

This allows calling #read after we've called #to_s.

This PR was motivated by httprb/http#437 (comment), where in httplog it was required to #rewind the form body after calling #to_s on it (source). I just thought that this was surprising behaviour, and that there is no reason why not rewind the content after calling #to_s on it.

Btw, I think it makes sense to still keep the #rewind before the #read, because httplog could one day decide they want to log the request data after the request has been made, at which point the form data objects would have been read. So then it would be nice to just be able to call #to_s and have it rewind the content automatically.

This allows calling #read after we've called #to_s.
@tycooon
Copy link

tycooon commented Feb 16, 2018

Doesn’t it break calling to_s after we called read? 🤔

@tycooon
Copy link

tycooon commented Feb 16, 2018

Just realized that’s what your last paragraph is about. Can’t we check the current state to figure out should we rewind or not?

@janko
Copy link
Member Author

janko commented Feb 16, 2018

Can’t we check the current state to figure out should we rewind or not?

We could theoretically track how many bytes we've read for each of the HTTP::FormData::* objects, but I don't see much benefit in that, because IMO rewinding should be cheap, especially if you're already at the beginning of the IO object.

@ixti ixti merged commit 6779a01 into httprb:master Feb 16, 2018
@ixti
Copy link
Member

ixti commented Feb 16, 2018

I was thinking about the same that probably we could track current position and return to it after reading the whole body. But then I realized that it will both:

  • change current behavior
  • makes not much sense

@ixti
Copy link
Member

ixti commented Feb 16, 2018

@janko-m Thank you!

@janko janko deleted the rewind-content-at-the-end-of-to_s branch February 16, 2018 20:08
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Mar 17, 2018
## 2.1.0 (2018-03-05)

* [#21](httprb/form_data#21)
  Rewind content at the end of `Readable#to_s`.
  [@janko-m][]

* [#19](httprb/form_data#19)
  Fix buffer encoding.
  [@HoneyryderChuck][]


## 2.0.0 (2017-10-01)

* [#17](httprb/form_data#17)
  Add CRLF character to end of multipart body.
  [@mhickman][]


## 2.0.0.pre2 (2017-05-11)

* [#14](httprb/form_data#14)
  Enable streaming for urlencoded form data.
  [@janko-m][]


## 2.0.0.pre1 (2017-05-10)

* [#12](httprb/form_data#12)
  Enable form data streaming.
  [@janko-m][]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants