Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions modules/openapi-generator/src/main/resources/python/rest.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ def is_socks_proxy_url(url):
else:
return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES

def contenttype_matches(contenttype, maintype, subtype):
pattern = '{type}/(?:[^+;]+\\+)?{subtype}(?:[ \t]*;.*)?'.format(
type = re.escape(maintype),
subtype = re.escape(subtype),
)
return re.fullmatch(pattern, contenttype, re.IGNORECASE) is not None

class RESTResponse(io.IOBase):

Expand Down Expand Up @@ -171,7 +177,7 @@ class RESTClientObject:
content_type = headers.get('Content-Type')
if (
not content_type
or re.search('json', content_type, re.IGNORECASE)
or contenttype_matches(content_type, 'application', 'json')
):
request_body = None
if body is not None:
Expand All @@ -184,7 +190,7 @@ class RESTClientObject:
headers=headers,
preload_content=False
)
elif content_type == 'application/x-www-form-urlencoded':
elif contenttype_matches(content_type, 'application', 'x-www-form-urlencoded'):
r = self.pool_manager.request(
method,
url,
Expand All @@ -194,7 +200,7 @@ class RESTClientObject:
headers=headers,
preload_content=False
)
elif content_type == 'multipart/form-data':
elif contenttype_matches(content_type, 'multipart', 'form-data'):
# must del headers['Content-Type'], or the correct
# Content-Type which generated by urllib3 will be
# overwritten.
Expand Down Expand Up @@ -222,7 +228,7 @@ class RESTClientObject:
headers=headers,
preload_content=False
)
elif headers['Content-Type'].startswith('text/') and isinstance(body, bool):
elif content_type.startswith('text/') and isinstance(body, bool):
request_body = "true" if body else "false"
r = self.pool_manager.request(
method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def is_socks_proxy_url(url):
else:
return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES

def contenttype_matches(contenttype, maintype, subtype):
pattern = '{type}/(?:[^+;]+\\+)?{subtype}(?:[ \t]*;.*)?'.format(
type = re.escape(maintype),
subtype = re.escape(subtype),
)
return re.fullmatch(pattern, contenttype, re.IGNORECASE) is not None

class RESTResponse(io.IOBase):

Expand Down Expand Up @@ -181,7 +187,7 @@ def request(
content_type = headers.get('Content-Type')
if (
not content_type
or re.search('json', content_type, re.IGNORECASE)
or contenttype_matches(content_type, 'application', 'json')
):
request_body = None
if body is not None:
Expand All @@ -194,7 +200,7 @@ def request(
headers=headers,
preload_content=False
)
elif content_type == 'application/x-www-form-urlencoded':
elif contenttype_matches(content_type, 'application', 'x-www-form-urlencoded'):
r = self.pool_manager.request(
method,
url,
Expand All @@ -204,7 +210,7 @@ def request(
headers=headers,
preload_content=False
)
elif content_type == 'multipart/form-data':
elif contenttype_matches(content_type, 'multipart', 'form-data'):
# must del headers['Content-Type'], or the correct
# Content-Type which generated by urllib3 will be
# overwritten.
Expand Down Expand Up @@ -232,7 +238,7 @@ def request(
headers=headers,
preload_content=False
)
elif headers['Content-Type'].startswith('text/') and isinstance(body, bool):
elif content_type.startswith('text/') and isinstance(body, bool):
request_body = "true" if body else "false"
r = self.pool_manager.request(
method,
Expand Down
14 changes: 10 additions & 4 deletions samples/client/echo_api/python/openapi_client/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def is_socks_proxy_url(url):
else:
return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES

def contenttype_matches(contenttype, maintype, subtype):
pattern = '{type}/(?:[^+;]+\\+)?{subtype}(?:[ \t]*;.*)?'.format(
type = re.escape(maintype),
subtype = re.escape(subtype),
)
return re.fullmatch(pattern, contenttype, re.IGNORECASE) is not None

class RESTResponse(io.IOBase):

Expand Down Expand Up @@ -181,7 +187,7 @@ def request(
content_type = headers.get('Content-Type')
if (
not content_type
or re.search('json', content_type, re.IGNORECASE)
or contenttype_matches(content_type, 'application', 'json')
):
request_body = None
if body is not None:
Expand All @@ -194,7 +200,7 @@ def request(
headers=headers,
preload_content=False
)
elif content_type == 'application/x-www-form-urlencoded':
elif contenttype_matches(content_type, 'application', 'x-www-form-urlencoded'):
r = self.pool_manager.request(
method,
url,
Expand All @@ -204,7 +210,7 @@ def request(
headers=headers,
preload_content=False
)
elif content_type == 'multipart/form-data':
elif contenttype_matches(content_type, 'multipart', 'form-data'):
# must del headers['Content-Type'], or the correct
# Content-Type which generated by urllib3 will be
# overwritten.
Expand Down Expand Up @@ -232,7 +238,7 @@ def request(
headers=headers,
preload_content=False
)
elif headers['Content-Type'].startswith('text/') and isinstance(body, bool):
elif content_type.startswith('text/') and isinstance(body, bool):
request_body = "true" if body else "false"
r = self.pool_manager.request(
method,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def is_socks_proxy_url(url):
else:
return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES

def contenttype_matches(contenttype, maintype, subtype):
pattern = '{type}/(?:[^+;]+\\+)?{subtype}(?:[ \t]*;.*)?'.format(
type = re.escape(maintype),
subtype = re.escape(subtype),
)
return re.fullmatch(pattern, contenttype, re.IGNORECASE) is not None

class RESTResponse(io.IOBase):

Expand Down Expand Up @@ -180,7 +186,7 @@ def request(
content_type = headers.get('Content-Type')
if (
not content_type
or re.search('json', content_type, re.IGNORECASE)
or contenttype_matches(content_type, 'application', 'json')
):
request_body = None
if body is not None:
Expand All @@ -193,7 +199,7 @@ def request(
headers=headers,
preload_content=False
)
elif content_type == 'application/x-www-form-urlencoded':
elif contenttype_matches(content_type, 'application', 'x-www-form-urlencoded'):
r = self.pool_manager.request(
method,
url,
Expand All @@ -203,7 +209,7 @@ def request(
headers=headers,
preload_content=False
)
elif content_type == 'multipart/form-data':
elif contenttype_matches(content_type, 'multipart', 'form-data'):
# must del headers['Content-Type'], or the correct
# Content-Type which generated by urllib3 will be
# overwritten.
Expand Down Expand Up @@ -231,7 +237,7 @@ def request(
headers=headers,
preload_content=False
)
elif headers['Content-Type'].startswith('text/') and isinstance(body, bool):
elif content_type.startswith('text/') and isinstance(body, bool):
request_body = "true" if body else "false"
r = self.pool_manager.request(
method,
Expand Down
14 changes: 10 additions & 4 deletions samples/openapi3/client/petstore/python/petstore_api/rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ def is_socks_proxy_url(url):
else:
return split_section[0].lower() in SUPPORTED_SOCKS_PROXIES

def contenttype_matches(contenttype, maintype, subtype):
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
pattern = '{type}/(?:[^+;]+\\+)?{subtype}(?:[ \t]*;.*)?'.format(
type = re.escape(maintype),
subtype = re.escape(subtype),
)
return re.fullmatch(pattern, contenttype, re.IGNORECASE) is not None

class RESTResponse(io.IOBase):

Expand Down Expand Up @@ -180,7 +186,7 @@ def request(
content_type = headers.get('Content-Type')
if (
not content_type
or re.search('json', content_type, re.IGNORECASE)
or contenttype_matches(content_type, 'application', 'json')
):
request_body = None
if body is not None:
Expand All @@ -193,7 +199,7 @@ def request(
headers=headers,
preload_content=False
)
elif content_type == 'application/x-www-form-urlencoded':
elif contenttype_matches(content_type, 'application', 'x-www-form-urlencoded'):
r = self.pool_manager.request(
method,
url,
Expand All @@ -203,7 +209,7 @@ def request(
headers=headers,
preload_content=False
)
elif content_type == 'multipart/form-data':
elif contenttype_matches(content_type, 'multipart', 'form-data'):
# must del headers['Content-Type'], or the correct
# Content-Type which generated by urllib3 will be
# overwritten.
Expand Down Expand Up @@ -231,7 +237,7 @@ def request(
headers=headers,
preload_content=False
)
elif headers['Content-Type'].startswith('text/') and isinstance(body, bool):
elif content_type.startswith('text/') and isinstance(body, bool):
request_body = "true" if body else "false"
r = self.pool_manager.request(
method,
Expand Down
Loading