Repository: falconry/falcon
Pull request #1474 (2019-03-06 00:37:43)

fix: omit the charset parameter from JSON media type

codecov[bot]: # [Codecov](https://codecov.io/gh/falconry/falcon/pull/1474?src=pr&el=h1) Report
> Merging [#1474](https://codecov.io/gh/falconry/falcon/pull/1474?src=pr&el=desc) into [master](https://codecov.io/gh/falconry/falcon/commit/4e24c6d4baa9d301433925b61c6ac61918c6c99f?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/falconry/falcon/pull/1474/graphs/tree.svg?width=650&token=zOtkfNQ3h6&height=150&src=pr)](https://codecov.io/gh/falconry/falcon/pull/1474?src=pr&el=tree)

```diff
@@          Coverage Diff           @@
##           master   #1474   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files          39      39           
  Lines        2613    2613           
  Branches      416     416           
======================================
  Hits         2613    2613
```


| [Impacted Files](https://codecov.io/gh/falconry/falcon/pull/1474?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [falcon/constants.py](https://codecov.io/gh/falconry/falcon/pull/1474/diff?src=pr&el=tree#diff-ZmFsY29uL2NvbnN0YW50cy5weQ==) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/falconry/falcon/pull/1474?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/falconry/falcon/pull/1474?src=pr&el=footer). Last update [4e24c6d...3b3e67c](https://codecov.io/gh/falconry/falcon/pull/1474?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

codecov[bot]: # [Codecov](https://codecov.io/gh/falconry/falcon/pull/1474?src=pr&el=h1) Report
> Merging [#1474](https://codecov.io/gh/falconry/falcon/pull/1474?src=pr&el=desc) into [master](https://codecov.io/gh/falconry/falcon/commit/4e24c6d4baa9d301433925b61c6ac61918c6c99f?src=pr&el=desc) will **not change** coverage.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/falconry/falcon/pull/1474/graphs/tree.svg?width=650&token=zOtkfNQ3h6&height=150&src=pr)](https://codecov.io/gh/falconry/falcon/pull/1474?src=pr&el=tree)

```diff
@@          Coverage Diff           @@
##           master   #1474   +/-   ##
======================================
  Coverage     100%    100%           
======================================
  Files          39      39           
  Lines        2613    2613           
  Branches      416     416           
======================================
  Hits         2613    2613
```


| [Impacted Files](https://codecov.io/gh/falconry/falcon/pull/1474?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [falcon/constants.py](https://codecov.io/gh/falconry/falcon/pull/1474/diff?src=pr&el=tree#diff-ZmFsY29uL2NvbnN0YW50cy5weQ==) | `100% <100%> (ø)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/falconry/falcon/pull/1474?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/falconry/falcon/pull/1474?src=pr&el=footer). Last update [4e24c6d...3b3e67c](https://codecov.io/gh/falconry/falcon/pull/1474?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

vytas7: Thanks for this PR @grktsh ,
we have indeed forgotten to include this change in the first alpha release, even though this change was clearly slated to be made for 2.0, good catch! Let's see if we can still carry this change into the 2.0 beta.

I think I have found one more case which needs to be ironed out wrt explicitly specifying charset, looking good otherwise!
kgriffs: According to my reading of RFC 7303 and https://www.w3.org/TR/xml/ (section 4.3.3) it is safe to leave off the charset for `application/xml` when the encoding is utf-8. I can take care of this in a separate PR. We'll also need to update the changelog for both of these changes.
kgriffs: @grktsh sorry about the mixup!
grktsh: @kgriffs Sorry!
vytas7: LGTM now, as my comments were addressed in https://github.com/falconry/falcon/pull/1476 :+1: 

Patch:
diff --git a/falcon/constants.py b/falcon/constants.py
index ab168fc..3f64e36 100644
--- a/falcon/constants.py
+++ b/falcon/constants.py
@@ -28,10 +28,7 @@ COMBINED_METHODS = HTTP_METHODS + WEBDAV_METHODS
 # UTF-8 and so it is the recommended default charset going forward,
 # and indeed, other charsets should not be specified to ensure
 # maximum interoperability.
-#
-# TODO(kgriffs) In Falcon 2.0, omit the charset parameter
-# below.
-MEDIA_JSON = 'application/json; charset=UTF-8'
+MEDIA_JSON = 'application/json'
 
 # NOTE(kgriffs): An internet media type for MessagePack has not
 # yet been registered. 'application/x-msgpack' is commonly used,


Test patch:
diff --git a/tests/test_response_media.py b/tests/test_response_media.py
index f6798ae..fa51738 100644
--- a/tests/test_response_media.py
+++ b/tests/test_response_media.py
@@ -133,7 +133,7 @@ def test_default_media_type():
     resp.media = {'something': True}
 
     assert json.loads(resp.data.decode('utf-8')) == {u'something': True}
-    assert resp.content_type == 'application/json; charset=UTF-8'
+    assert resp.content_type == 'application/json'
 
 
 def test_mimeparse_edgecases():