Skip to content

Commit

Permalink
http_client header
Browse files Browse the repository at this point in the history
  • Loading branch information
TimWang committed Jul 5, 2024
1 parent 173fbeb commit 8f8b5db
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

class DefaultOAuth2TokenProvider(OAuth2TokenProvider):
"""This class is the default implement of OAuth2TokenProvider."""

_credential: Optional[str]
_scope: Optional[str]
_path: Optional[str]
Expand Down
27 changes: 15 additions & 12 deletions clients/client-python/gravitino/utils/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,17 @@ def json(self):


class HTTPClient:

FORMDATA_HEADER = {
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/vnd.gravitino.v1+json",
}

JSON_HEADER = {
"Content-Type": "application/json",
"Accept": "application/vnd.gravitino.v1+json",
}

def __init__(
self,
host,
Expand Down Expand Up @@ -136,24 +147,16 @@ def _request(
method = method.upper()
request_data = None

if headers:
self._update_headers(headers)

if data:
request_data = urlencode(data.to_dict()).encode()
headers = {
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/vnd.gravitino.v1+json",
}
self._update_headers(headers)
self._update_headers(self.FORMDATA_HEADER)
else:
if json:
request_data = json.to_json().encode("utf-8")

headers = {
"Content-Type": "application/json",
"Accept": "application/vnd.gravitino.v1+json",
}
self._update_headers(self.JSON_HEADER)

if headers:
self._update_headers(headers)

opener = build_opener()
Expand Down

0 comments on commit 8f8b5db

Please sign in to comment.