HomeMesosphereNo notifications. 4 unresolved issues.

ping: provide a content-type that is better aligned with client expectations
ClosedAll Users

Authored by jdef on Jul 7 2017, 12:30 AM.

Details

Summary

Prefer dynamic content generation via static; the static content type established by the annotations
isn't very flexible and is not backwards compatible. This change set eliminates the static annotations
in favor of assessing the content type requested by the client and attempting to give it what it wants,
falling back to HTTP 204 (no content) if there's not a suitable match.

  • Any client Accept header that matches application/json will get a "pong" JSON object.
  • Any client Accept header that matches text/* will get a pong text string.
  • Lack of an Accept header will get a pong text string.
  • An Accept header for an unsupported type like image/png should yield an HTTP 204 response

xref D900

Test Plan
  • sbt test
  • system integration testing

Diff Detail

Repository
rMARATHON marathon
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
Changes from before your most recent comment are hidden. Show Older Changes
In D911#35859, @jdef wrote:

I've identified the additional changes required to avoid the exception above. Will push updates shortly.

@jeschkies it looks like you requested changes, but I don't see any comments re: the changes you're actually requesting. Please elaborate

I did not request changes. I would like to see @kensipe's ping.py.

jdef edited the summary of this revision. (Show Details)Jul 12 2017, 3:28 PM
kensipe requested changes to this revision.Jul 13 2017, 10:10 PM

response is still "pong" instead of pong. makes sense for "pong" in json... however it is a change from previous message in text.

Here is the pinger.py. It requires the installation of shakedown.

 cat ping.py 
from shakedown import http

# headers = { 'Accept' : '*/*'}
# response = http.get('http://localhost:8080/ping', headers=headers)

response = http.get('http://localhost:8080/ping')

print(response)
print(response.status_code)
print(response.text)
kensipe accepted this revision.Jul 13 2017, 10:35 PM

The dcos-cli libs used by shakedown actually make a request that includes Accept: application/json. Tests against curl proves this works as advertised. This fixes the previous issue. Nice work!

The request by dcos-cli: http.py is:

Accept: application/json
User-Agent: python-requests/2.18.0
Accept-Encoding: gzip, deflate
Connection: keep-alive
This revision is now accepted and ready to land.Jul 13 2017, 10:35 PM
jeschkies accepted this revision.Jul 17 2017, 11:07 AM
In D911#36141, @kensipe wrote:

response is still "pong" instead of pong. makes sense for "pong" in json... however it is a change from previous message in text.

Here is the pinger.py. It requires the installation of shakedown.

 cat ping.py 
from shakedown import http

# headers = { 'Accept' : '*/*'}
# response = http.get('http://localhost:8080/ping', headers=headers)

response = http.get('http://localhost:8080/ping')

print(response)
print(response.status_code)
print(response.text)

Thanks for the code!

This revision was automatically updated to reflect the committed changes.