MCPcopy Create free account
hub / github.com/apache/mesos / api

Method api

src/slave/http.cpp:369–538  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

367
368
369Future<Response> Http::api(
370 const Request& request,
371 const Option<Principal>& principal) const
372{
373 // TODO(anand): Add metrics for rejected requests.
374
375 if (slave->state == Slave::RECOVERING) {
376 return ServiceUnavailable("Agent has not finished recovery");
377 }
378
379 if (request.method != "POST") {
380 return MethodNotAllowed({"POST"}, request.method);
381 }
382
383 Option<string> contentType_ = request.headers.get("Content-Type");
384 if (contentType_.isNone()) {
385 return BadRequest("Expecting 'Content-Type' to be present");
386 }
387
388 ContentType contentType;
389 if (contentType_.get() == APPLICATION_JSON) {
390 contentType = ContentType::JSON;
391 } else if (contentType_.get() == APPLICATION_PROTOBUF) {
392 contentType = ContentType::PROTOBUF;
393 } else if (contentType_.get() == APPLICATION_RECORDIO) {
394 contentType = ContentType::RECORDIO;
395 } else {
396 return UnsupportedMediaType(
397 string("Expecting 'Content-Type' of ") +
398 APPLICATION_JSON + " or " + APPLICATION_PROTOBUF +
399 + " or " + APPLICATION_RECORDIO);
400 }
401
402 Option<ContentType> messageContentType;
403 Option<string> messageContentType_ =
404 request.headers.get(MESSAGE_CONTENT_TYPE);
405
406 if (streamingMediaType(contentType)) {
407 if (messageContentType_.isNone()) {
408 return BadRequest(
409 "Expecting '" + stringify(MESSAGE_CONTENT_TYPE) + "' to be" +
410 " set for streaming requests");
411 }
412
413 if (messageContentType_.get() == APPLICATION_JSON) {
414 messageContentType = Option<ContentType>(ContentType::JSON);
415 } else if (messageContentType_.get() == APPLICATION_PROTOBUF) {
416 messageContentType = Option<ContentType>(ContentType::PROTOBUF);
417 } else {
418 return UnsupportedMediaType(
419 string("Expecting '") + MESSAGE_CONTENT_TYPE + "' of " +
420 APPLICATION_JSON + " or " + APPLICATION_PROTOBUF);
421 }
422 } else {
423 // Validate that a client has not set the "Message-Content-Type"
424 // header for a non-streaming request.
425 if (messageContentType_.isSome()) {
426 return UnsupportedMediaType(

Callers 3

TEST_FFunction · 0.45
TEST_PFunction · 0.45
initializeMethod · 0.45

Calls 15

ServiceUnavailableClass · 0.85
MethodNotAllowedClass · 0.85
BadRequestClass · 0.85
streamingMediaTypeFunction · 0.85
NotAcceptableClass · 0.85
deferFunction · 0.85
NoneClass · 0.85
acceptsMediaTypeMethod · 0.80
readAllMethod · 0.80
validateFunction · 0.70
errorMethod · 0.65

Tested by 2

TEST_FFunction · 0.36
TEST_PFunction · 0.36