Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Tensorflow Serving EvHTTP Request

From Leeroopedia
Revision as of 13:53, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Tensorflow_Serving_EvHTTP_Request.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains HTTP, Networking
Last Updated 2026-02-13 00:00 GMT

Overview

A libevent-based implementation of the ServerRequestInterface that wraps evhttp_request to provide HTTP request parsing, response writing, gzip decompression, and reply dispatching.

Description

EvHTTPRequest implements the ServerRequestInterface and wraps a ParsedEvRequest which contains the decoded libevent request. ParsedEvRequest parses the incoming evhttp_request to extract the HTTP method (GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE, CONNECT, PATCH), URI, path, query, fragment, and headers. EvHTTPRequest provides: ReadRequestBytes() to read the request body (with automatic gzip decompression when Content-Encoding indicates gzip and the handler has auto_uncompress_input enabled), WriteResponseBytes()/WriteResponseString() to append data to the output buffer, GetRequestHeader() and request_headers() for header access, OverwriteResponseHeader()/AppendResponseHeader() for setting response headers, and ReplyWithStatus()/Reply()/Abort() for completing the response. Replies are scheduled on the libevent event loop via EventLoopSchedule to ensure thread safety with libevent's single-threaded model. The request object deletes itself after sending the reply via EvSendReply.

Usage

This is the internal request implementation used by EvHTTPServer. Application code interacts with it through the ServerRequestInterface abstraction when handling HTTP requests in the serving system.

Code Reference

Source Location

  • Repository: Tensorflow_Serving
  • File: tensorflow_serving/util/net_http/server/internal/evhttp_request.cc
  • Lines: 1-389

Signature

struct ParsedEvRequest {
  explicit ParsedEvRequest(evhttp_request* request_in);
  ~ParsedEvRequest();
  bool decode();

  evhttp_request* request;
  evhttp_uri* decoded_uri;
  std::string method;
  const char* uri;
  const char* path;
  std::string path_and_query;
  evkeyvalq* headers;
};

class EvHTTPRequest : public ServerRequestInterface {
 public:
  EvHTTPRequest(std::unique_ptr<ParsedEvRequest> request, ServerSupport* server);
  bool Initialize();
  absl::string_view uri_path() const override;
  absl::string_view http_method() const override;
  void WriteResponseBytes(const char* data, int64_t size) override;
  void WriteResponseString(absl::string_view data) override;
  std::unique_ptr<char[], BlockDeleter> ReadRequestBytes(int64_t* size) override;
  void ReplyWithStatus(HTTPStatusCode status) override;
  void Reply() override;
  void Abort() override;
};

Import

#include "tensorflow_serving/util/net_http/server/internal/evhttp_request.h"

I/O Contract

Inputs

Name Type Required Description
request evhttp_request* Yes The raw libevent HTTP request
server ServerSupport* Yes The server support interface for event loop scheduling

Outputs

Name Type Description
uri_path() absl::string_view The request path including query and fragment
http_method() absl::string_view The HTTP method string (e.g., "GET", "POST")
ReadRequestBytes() std::unique_ptr<char[], BlockDeleter> The request body bytes, optionally gzip-decompressed

Usage Examples

Handling a Request (Application Code)

// This is how application code sees the request through the interface
void MyHandler(ServerRequestInterface* request) {
  int64_t size;
  auto body = request->ReadRequestBytes(&size);
  if (body != nullptr) {
    ProcessBody(body.get(), size);
  }
  request->WriteResponseString("OK");
  request->Reply();
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment