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

Allow gzip compression in high-level server response interface #403

Merged
merged 1 commit into from
Jun 17, 2015
Merged

Allow gzip compression in high-level server response interface #403

merged 1 commit into from
Jun 17, 2015

Conversation

danielnelson
Copy link
Contributor

Add encoding kwarg to enable_compression to select gzip or deflate and
set Content-Encoding header.

This is for issue #396.

I have a few concerns about this code:

I think that when using a high level interface one would generally want to simply enable all types of compression that are supported by the library, with selection automatically made based on the Accept-Encoding header. Potentially one may want to optionally specify a subset of the available encoding types, such as if we had compress support, maybe one would want to allow gzip and compress but not deflate.

I considered changing the signature to accept a sequence of encodings, however if we do this it is no longer intuitive to me how the force argument behaves.

Let me know how you think it would best to proceed.

@asvetlov
Copy link
Member

asvetlov commented Jun 9, 2015

Please fix pep8 errors

@asvetlov
Copy link
Member

asvetlov commented Jun 9, 2015

Maybe force parameter should accept False, True (synonym for 'deflate'), 'deflate' and 'gzip'?
Does it make sense?

@fafhrd91
Copy link
Member

fafhrd91 commented Jun 9, 2015

Enum with 3 values?

@asvetlov
Copy link
Member

asvetlov commented Jun 9, 2015

@fafhrd91 I believe enum is the perfect solution but we still should support True and False without breaking backward compatibility.
Also IIRC enum library is not available in Python 3.3. Would you add https://pythonhosted.org/flufl.enum/ as requered dependency?

@fafhrd91
Copy link
Member

fafhrd91 commented Jun 9, 2015

Let's drop py3.3 support

@ludovic-gasc
Copy link
Contributor

Let's drop py3.3 support

+1

@asvetlov
Copy link
Member

asvetlov commented Jun 9, 2015

@fafhrd91 you are moving too fast from my perspective.
I'd like to support 3.3 until 3.5 release at least.

Anyway, how enum may process True and False? That's required for aiohttp backward compatibility.
Do you suggest accepting both bool and enum for force parameter? That makes sense.

@fafhrd91
Copy link
Member

fafhrd91 commented Jun 9, 2015

I prefer to use enum. Is flufl.enum compatible with py3.4 enums?
I am fine with enum dependency

@asvetlov
Copy link
Member

asvetlov commented Jun 9, 2015

It's fully compatible and it is the base library for standard enum.

@fafhrd91
Copy link
Member

fafhrd91 commented Jun 9, 2015

Lets then just use enum

@danielnelson
Copy link
Contributor Author

Okay so based on this discussion here is a rough draft of what the new documentation might look like:

.. method:: enable_compression(force=None, *, encodings=None)

Enable compression.

When *force* is unset (default) compression encoding is
selected based on the :class:`TransferEncoding` in *encodings*
and the *Accept-Encoding* request header.  The default encodings
are :class:`TransferEncoding.deflate` and
:class:`TransferEncoding.gzip`.

When *force* is set to a :class:`TransferEncoding`, this encoding
will be used and *Accept-Encoding* is not checked.

If *force* is set to ``True``, :class:`TransferEncoding.deflate`
will be used.

@asvetlov
Copy link
Member

@danielnelson did you mean .. method:: enable_compression(force=None) ?

@danielnelson
Copy link
Contributor Author

I'm not sure I understand. Are you saying you don't expect a encodings kwarg or are you asking about the default value of force?

@asvetlov
Copy link
Member

I say encoding is redundant and force should accept True/False for backward compatibility and TransferEncoding for actual encoding specification. False is alias for TransferEncoding.plain, True for TransferEncoding.deflate.

@fafhrd91
Copy link
Member

I wouldn't worry about backward compatibility here.

@asvetlov
Copy link
Member

Sorry, but I do care about backward compatibility.
Maybe the compromise is:

  1. introduce compress property and enable_compress(transfer_encoding: TransferEncoding) method.
  2. Deprecate compression and enable_compression().
  3. Call new API from deprecated one.

@asvetlov
Copy link
Member

content_coding is the term used by RFC 2616, we can use this name.
But maybe it's sounds a bit confusing.

@asvetlov
Copy link
Member

compress is a verb but content_coding is a noun.

@danielnelson
Copy link
Contributor Author

Anywhere I said transfer encoding above should definitely be content coding, and of course the header is Content-Encoding.

Having backwards compatibility here wouldn't introduce too much cruft, and I also think we are not completely sure what we would need from a compress interface. So I would prefer to just add backwards compatibility for now.

@@ -72,6 +77,11 @@ def content_length(self, _CONTENT_LENGTH=hdrs.CONTENT_LENGTH):
FileField = collections.namedtuple('Field', 'name filename file content_type')


class ContentCoding(enum.Enum):
deflate = 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use str values: deflate = 'deflate'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also would like to note that this list of encodings is not complete. Never saw compress in the wild, however, but identity is pretty common one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is the current list of registered codings. I'll add a comment about how this is enum only represents our supported coding types.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good finding! Please add a comment with this link

@danielnelson
Copy link
Contributor Author

I have updated the pull request with the suggested changes.

@asvetlov
Copy link
Member

LGTM

asvetlov added a commit that referenced this pull request Jun 17, 2015
…ression

Allow gzip compression in high-level server response interface
@asvetlov asvetlov merged commit fb3938a into aio-libs:master Jun 17, 2015
@asvetlov
Copy link
Member

Merged. @danielnelson thanks for patience :)

@lock
Copy link

lock bot commented Oct 30, 2019

This thread has been automatically locked since there has not been
any recent activity after it was closed. Please open a new issue for
related bugs.

If you feel like there's important points made in this discussion,
please include those exceprts into that new issue.

@lock lock bot added the outdated label Oct 30, 2019
@lock lock bot locked as resolved and limited conversation to collaborators Oct 30, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants