Repository: Azure/msrest-for-python

Issue:
Response content type json parser
Currently the deserializer only supports a list of content type values like "application/json" and "text/json".  Based on HTTP spec, "application/<randomtext>+json" is also json. So we should have a type parser to accept this syntax. 

Discussion:
codecov-io: # [Codecov](https://codecov.io/gh/Azure/msrest-for-python/pull/167?src=pr&el=h1) Report
> Merging [#167](https://codecov.io/gh/Azure/msrest-for-python/pull/167?src=pr&el=desc) into [master](https://codecov.io/gh/Azure/msrest-for-python/commit/c4086bfac4e45b11b6bd4267cff62aa302a51877?src=pr&el=desc) will **increase** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/Azure/msrest-for-python/pull/167/graphs/tree.svg?width=650&token=Lny6ZO1MUF&height=150&src=pr)](https://codecov.io/gh/Azure/msrest-for-python/pull/167?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master     #167      +/-   ##
==========================================
+ Coverage   87.84%   87.84%   +<.01%     
==========================================
  Files          25       25              
  Lines        2583     2584       +1     
==========================================
+ Hits         2269     2270       +1     
  Misses        314      314
```


| [Impacted Files](https://codecov.io/gh/Azure/msrest-for-python/pull/167?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [msrest/pipeline/universal.py](https://codecov.io/gh/Azure/msrest-for-python/pull/167/diff?src=pr&el=tree#diff-bXNyZXN0L3BpcGVsaW5lL3VuaXZlcnNhbC5weQ==) | `95.09% <100%> (+0.04%)` | :arrow_up: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/Azure/msrest-for-python/pull/167?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/Azure/msrest-for-python/pull/167?src=pr&el=footer). Last update [c4086bf...852f412](https://codecov.io/gh/Azure/msrest-for-python/pull/167?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/msrest/pipeline/universal.py b/msrest/pipeline/universal.py
index f124ea7..b8dc40c 100644
--- a/msrest/pipeline/universal.py
+++ b/msrest/pipeline/universal.py
@@ -32,6 +32,7 @@ import os
 import xml.etree.ElementTree as ET
 import platform
 import codecs
+import re
 
 from typing import Mapping, Any, Optional, AnyStr, Union, IO, cast, TYPE_CHECKING  # pylint: disable=unused-import
 
@@ -129,10 +130,9 @@ class HTTPLogger(SansIOHTTPPolicy):
 
 class RawDeserializer(SansIOHTTPPolicy):
 
-    JSON_MIMETYPES = [
-        'application/json',
-        'text/json' # Because we're open minded people...
-    ]
+    # Accept "text" because we're open minded people...
+    JSON_REGEXP = re.compile(r'^(application|text)/([a-z+.]+\+)?json$')
+
     # Name used in context
     CONTEXT_NAME = "deserialized_data"
 
@@ -165,7 +165,7 @@ class RawDeserializer(SansIOHTTPPolicy):
         if content_type is None:
             return data
 
-        if content_type in cls.JSON_MIMETYPES:
+        if cls.JSON_REGEXP.match(content_type):
             try:
                 return json.loads(data_as_str)
             except ValueError as err:


Test patch:
diff --git a/tests/test_universal_pipeline.py b/tests/test_universal_pipeline.py
index 2568e34..cd92ca7 100644
--- a/tests/test_universal_pipeline.py
+++ b/tests/test_universal_pipeline.py
@@ -151,6 +151,12 @@ def test_raw_deserializer():
     result = response.context["deserialized_data"]
     assert result["success"] is True
 
+    # Simple JSON with complex content_type
+    response = build_response(b'{"success": true}', content_type="application/vnd.microsoft.appconfig.kv+json")
+    raw_deserializer.on_response(None, response, stream=False)
+    result = response.context["deserialized_data"]
+    assert result["success"] is True
+
     # JSON with UTF-8 BOM
     response = build_response(b'\xef\xbb\xbf{"success": true}', content_type="application/json; charset=utf-8")
     raw_deserializer.on_response(None, response, stream=False)