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

Add MIME::MediaType #7077

Merged
merged 2 commits into from Jan 10, 2019

Conversation

Projects
None yet
6 participants
@straight-shoota
Copy link
Member

straight-shoota commented Nov 13, 2018

This PR adds a MIME::MediaType type with methods for parsing mime media types as per RFC 2045 and RFC 2046 including support for optional parameters.

This type is put to use for reading and writing HTTP Content-Type headers and HTTP::Multipart boundaries replacing existing incomplete implementations.

This is not directly integrated with the MIME registry (added in #5765) but can be optionally used together.

Closes #5686

Show resolved Hide resolved spec/std/mime/media_type_spec.cr Outdated
Show resolved Hide resolved src/mime/media_type.cr Outdated
Show resolved Hide resolved src/mime/media_type.cr Outdated
Show resolved Hide resolved src/mime/media_type.cr Outdated
Show resolved Hide resolved src/mime/media_type.cr Outdated

@straight-shoota straight-shoota force-pushed the straight-shoota:jm/feature/mime-media-type branch from fd7b793 to e01f1aa Nov 14, 2018

@RX14
Copy link
Member

RX14 left a comment

Needs code comments on the "tricky bits", especially the rfc2231 handling

Show resolved Hide resolved src/mime/media_type.cr Outdated
Show resolved Hide resolved src/mime/media_type.cr Outdated
Show resolved Hide resolved src/mime/media_type.cr Outdated
Show resolved Hide resolved src/mime/media_type.cr Outdated
@@ -5,8 +5,7 @@ require "mime"
module MIME
# A MediaType describes a MIME content type with optional parameters.
struct MediaType
property media_type : String
property params : Hash(String, String)

This comment has been minimized.

@Sija

Sija Nov 26, 2018

Contributor

Why? Having access to raw params Hash could come handy, when removed there's no way to do that.

This comment has been minimized.

@straight-shoota

straight-shoota Nov 26, 2018

Author Member

MediaType directly exposes #[], #[]?, #fetch, #[]= and #each_parameter. Why would yo need direct access to params?

This comment has been minimized.

@Sija

Sija Nov 26, 2018

Contributor

For serialization as an example.

This comment has been minimized.

@straight-shoota

straight-shoota Nov 26, 2018

Author Member

What kind of serialization? I figure you'd either serialize with #to_s or directly access the ivar @params.

@straight-shoota straight-shoota force-pushed the straight-shoota:jm/feature/mime-media-type branch from ffb4b52 to da6ce50 Nov 26, 2018

Show resolved Hide resolved src/mime/media_type.cr Outdated
Show resolved Hide resolved src/mime/media_type.cr Outdated

@straight-shoota straight-shoota force-pushed the straight-shoota:jm/feature/mime-media-type branch from 90de96c to 92d2b18 Dec 5, 2018

@straight-shoota

This comment has been minimized.

Copy link
Member Author

straight-shoota commented Dec 5, 2018

@RX14 I removed sort from #to_s without an different implementation for #inspect. This can be improved later, if necessary.

@straight-shoota straight-shoota force-pushed the straight-shoota:jm/feature/mime-media-type branch from 92d2b18 to 3663040 Dec 6, 2018

@RX14
Copy link
Member

RX14 left a comment

I'd still like many more code comments to explain the implicit state while parsing. Especially the rfc2231 stuff.

Show resolved Hide resolved spec/std/mime/media_type_spec.cr
Show resolved Hide resolved src/mime/media_type.cr Outdated
Show resolved Hide resolved src/mime/media_type.cr Outdated
@RX14

RX14 approved these changes Dec 16, 2018

Show resolved Hide resolved src/mime/media_type.cr Outdated
Show resolved Hide resolved src/mime/media_type.cr Outdated
Show resolved Hide resolved src/mime/media_type.cr Outdated
Show resolved Hide resolved src/mime/media_type.cr Outdated
Show resolved Hide resolved src/mime/media_type.cr Outdated
@sdogruyol
Copy link
Member

sdogruyol left a comment

Finally, thank you @straight-shoota 👍

Show resolved Hide resolved src/mime/media_type.cr
@RX14

RX14 approved these changes Dec 20, 2018

@RX14 RX14 added this to the 0.27.1 milestone Dec 20, 2018

@RX14

This comment has been minimized.

Copy link
Member

RX14 commented Dec 20, 2018

Squash please!

@straight-shoota straight-shoota force-pushed the straight-shoota:jm/feature/mime-media-type branch 2 times, most recently from c083d5f to 623ffca Dec 22, 2018

@straight-shoota straight-shoota force-pushed the straight-shoota:jm/feature/mime-media-type branch from 623ffca to f4f1151 Dec 22, 2018

@sdogruyol sdogruyol merged commit fc4360b into crystal-lang:master Jan 10, 2019

4 checks passed

ci/circleci: test_darwin Your tests passed on CircleCI!
Details
ci/circleci: test_linux Your tests passed on CircleCI!
Details
ci/circleci: test_linux32 Your tests passed on CircleCI!
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

@straight-shoota straight-shoota deleted the straight-shoota:jm/feature/mime-media-type branch Jan 10, 2019

urde-graven pushed a commit to urde-graven/crystal that referenced this pull request Jan 12, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment