Skip to content

Commit 0ee010b

Browse files
authored
Merge pull request #142 from minjikarin/httpoverride
added HTTP override
2 parents 87f37fa + 433c85d commit 0ee010b

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

amadeus/client/request.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,16 @@ def __build_user_agent(self):
8484
user_agent += ' {0}/{1}'.format(self.app_id, self.app_version)
8585
return user_agent
8686

87+
# The list of paths that require HTTP override in header
88+
list_httpoverride = [
89+
'/v2/shopping/flight-offers',
90+
'/v1/shopping/seatmaps',
91+
'/v1/shopping/availability/flight-availabilities',
92+
'/v2/shopping/flight-offers/prediction',
93+
'/v1/shopping/flight-offers/pricing?',
94+
'/v1/shopping/flight-offers/upselling'
95+
]
96+
8797
# Builds a HTTP Request object based on the path, params, and verb
8898
def __build_http_request(self):
8999
# Requests token in case has not been set
@@ -92,11 +102,13 @@ def __build_http_request(self):
92102
return HTTPRequest(self.url,
93103
data=urlencode(self.params).encode(),
94104
headers=self.headers)
95-
96105
# Adds the authentication header since the bearer token has been set
97106
self.headers['Authorization'] = self.bearer_token
98107

99108
if self.verb == 'POST':
109+
# Adds HTTP override in Header for the list of paths required
110+
if self.path in Request.list_httpoverride:
111+
self.headers['X-HTTP-Method-Override'] = 'GET'
100112
if type(self.params) is dict:
101113
return HTTPRequest(self.url, headers=self.headers, method='POST',
102114
data=json.dumps(self.params).encode())

specs/client/request_spec.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,28 @@
8686
expect(self.request.http_request.data).to(
8787
equal(b'{\"foo\": \"bar\"}'))
8888

89+
with it('should return X-HTTP-Method-Override in header'
90+
'for the listed POST requests'):
91+
for path in Request.list_httpoverride:
92+
self.request = Request({
93+
'host': self.host,
94+
'verb': 'POST',
95+
'path': path,
96+
'params': self.params,
97+
'bearer_token': self.bearer_token,
98+
'client_version': self.client_version,
99+
'language_version': self.lang_version,
100+
'app_id': self.app_id,
101+
'app_version': self.app_version,
102+
'port': self.port,
103+
'ssl': self.ssl
104+
})
105+
106+
expect(self.request.http_request).to(be_a(HTTPRequest))
107+
expect(self.request.headers['X-HTTP-Method-Override']).to(
108+
equal('GET')
109+
)
110+
89111
with it('should handle a custom scheme and port'):
90112
self.request = Request({
91113
'host': self.host,

0 commit comments

Comments
 (0)