| 2581 | |
| 2582 | |
| 2583 | void ProcessManager::handle( |
| 2584 | const Socket& socket, |
| 2585 | Request* request) |
| 2586 | { |
| 2587 | CHECK(request != nullptr); |
| 2588 | |
| 2589 | // Start by checking that the path starts with a '/'. |
| 2590 | if (request->url.path.find('/') != 0) { |
| 2591 | VLOG(1) << "Returning '400 Bad Request' for '" << request->url.path << "'"; |
| 2592 | |
| 2593 | // Get the HttpProxy pid for this socket. |
| 2594 | PID<HttpProxy> proxy = socket_manager->proxy(socket); |
| 2595 | |
| 2596 | // Enqueue the response with the HttpProxy so that it respects the |
| 2597 | // order of requests to account for HTTP/1.1 pipelining. |
| 2598 | dispatch( |
| 2599 | proxy, |
| 2600 | &HttpProxy::enqueue, |
| 2601 | BadRequest("Request URL path must start with '/'"), |
| 2602 | *request); |
| 2603 | |
| 2604 | // Cleanup request. |
| 2605 | delete request; |
| 2606 | return; |
| 2607 | } |
| 2608 | |
| 2609 | // Check if this is a libprocess request (i.e., 'User-Agent: |
| 2610 | // libprocess/id@ip:port') and if so, parse as a message. |
| 2611 | if (libprocess(request)) { |
| 2612 | // It is guaranteed that the continuation would run before the next |
| 2613 | // request arrives. Also, it's fine to pass the `this` pointer to the |
| 2614 | // continuation as this would get executed synchronously (if still pending) |
| 2615 | // from `SocketManager::finalize()` due to it closing all active sockets |
| 2616 | // during libprocess finalization. |
| 2617 | parse(*request) |
| 2618 | .onAny([socket, request](const Future<MessageEvent*>& future) { |
| 2619 | // Get the HttpProxy pid for this socket. |
| 2620 | PID<HttpProxy> proxy = socket_manager->proxy(socket); |
| 2621 | |
| 2622 | if (!future.isReady()) { |
| 2623 | Response response = InternalServerError( |
| 2624 | future.isFailed() ? future.failure() : "discarded future"); |
| 2625 | |
| 2626 | dispatch(proxy, &HttpProxy::enqueue, response, *request); |
| 2627 | |
| 2628 | VLOG(1) << "Returning '" << response.status << "' for '" |
| 2629 | << request->url.path << "': " << response.body; |
| 2630 | |
| 2631 | delete request; |
| 2632 | return; |
| 2633 | } |
| 2634 | |
| 2635 | MessageEvent* event = CHECK_NOTNULL(future.get()); |
| 2636 | |
| 2637 | // Verify that the UPID this peer is claiming is on the same IP |
| 2638 | // address the peer is sending from. |
| 2639 | if (libprocess_flags->require_peer_address_ip_match) { |
| 2640 | CHECK_SOME(request->client); |
no test coverage detected