Introducing a new way to review your PRs.

Read the announcement

combodo / itop

A simple, web based CMDB & IT Service Management tool

View on GitHub

17 documents · Updated Nov 20, 2026

docs / http-request-contracts

HTTP request contracts

The application HTTP contract gives endpoint code a common way to describe input parameters, validate them, classify bad requests, and send a clear result. It keeps request checks and response status handling separate from the business action that the endpoint performs. See Application experience, Request routing and UI rendering, and Identity and user state for the wider request flow.

Request boundary

The request boundary is the point where endpoint code turns untrusted HTTP input into values that the application can use. HttpRequest owns this boundary for the newer application-level helpers and also protects AJAX endpoints from unapproved calls.

Request parameter declarations

RequestParamDTO is a parameter declaration. It names the input, selects GET or POST input, chooses a sanitization filter, and states whether the input is required or has a default value. Endpoint code declares parameters before it reads them, so the declaration carries the input contract next to the endpoint action. The Get, Post, and Create factories provide the main forms of that declaration.

References: sources/…/RequestParamDTO.php• L20-40

Parameter extraction

HttpRequest::HandleRequestParam processes parameter declarations in order and returns an array with the matching values in that same order. It reads POST values through the posted-input path and other values through the general request path. Each path applies the sanitization filter from the declaration before the endpoint receives the value.

A required parameter with no value becomes a bad request. The helper sets the HTTP status to 400, records request details in the web-request log, and raises HttpBadRequestException so the endpoint can stop normal processing.

References: sources/…/HttpRequest.php• L52-91

AJAX endpoint checks

HttpRequest::CheckAjaxEndpoint is the request-level security check for AJAX calls. After login, it requires the X-Combodo-Ajax header unless the endpoint explicitly allows a bypass method. If the header is absent, a valid transaction token can satisfy the check; otherwise the helper logs the event and raises SecurityException.

This check belongs after login because the transaction token depends on the logged-in request state. A caller that fails this check is unauthorized rather than merely malformed.

References: sources/…/HttpRequest.php• L25-49 datamodels/…/ajax.itop-attachment.php• L129-143

Request outcomes

Endpoint code communicates outcomes through HTTP status codes and a response body format that matches the caller. The response helper centralizes the headers, body encoding, and final exit for the small set of outcomes used by these endpoints.

Response formats

HttpResponse supports JSON responses for data clients and plain-text responses for simple status failures. The JSON helper sets an application JSON content type and encodes an array. The plain-text helper sets a text content type and sends the supplied message.

The named failure helpers map common endpoint failures to stable outcomes:

  • SendTextPlainBadRequestResponseAndExit sends status 400.
  • SendTextPlainUnauthorizedResponseAndExit sends status 401.
  • SendTextPlainFatalResponseAndExit sends status 500.

Each helper exits after sending the response, so callers do not continue into endpoint work after an outcome is returned.

References: sources/…/HttpResponse.php• L20-51

Bad-request exception

HttpBadRequestException is the application exception that marks invalid request input. It extends the common CoreException type and carries the failure from parameter validation to the endpoint boundary. The exception does not send a response by itself; the endpoint catch block chooses the response format and terminates the request.

References: sources/…/HttpBadRequestException.php• L8-21 sources/…/HttpRequest.php• L70-85

Endpoint usage

An endpoint uses the contract in a short sequence: establish request security, declare and extract inputs, run the action, then translate known failures into HTTP outcomes. The attachment AJAX endpoint shows this pattern for both an operation selector and operation-specific parameters.

This diagram shows how declared input and raised exceptions become the final HTTP response.

sequenceDiagram
    participant Client
    participant Endpoint
    participant HttpRequest
    participant Action
    participant HttpResponse

    Client->>Endpoint: AJAX request
    Endpoint->>HttpRequest: CheckAjaxEndpoint()
    HttpRequest-->>Endpoint: Security accepted
    Endpoint->>HttpRequest: HandleRequestParam(declarations)
    HttpRequest-->>Endpoint: Ordered values
    Endpoint->>Action: Run operation
    Action-->>Endpoint: Result
    Endpoint->>HttpResponse: Send response and exit
    HttpResponse-->>Client: Status, content type, body

Attachment endpoint flow

The attachment endpoint first authenticates the caller and checks the AJAX boundary. It then requires an operation name, selects the matching action, and declares the action's own inputs with the filters and required state that apply to them.

When input is missing, the parameter helper raises HttpBadRequestException before the action runs. The outer handler returns a localized plain-text 400 response. A failed AJAX security check returns 401, while an unexpected exception returns 500.

References: datamodels/…/ajax.itop-attachment.php• L129-163 datamodels/…/ajax.itop-attachment.php• L44-53 datamodels/…/ajax.itop-attachment.php• L101-126

Legacy AJAX boundary

The shared pages/ajax.render.php endpoint uses the same AJAX security check and response helper even though its operation parameters are read through older request utilities. It allows GET to bypass the AJAX header check and converts a failed security check to the same plain-text 401 response.

This makes the request contract useful at the boundary without requiring every older operation in the dispatcher to use the newer parameter declaration type.

References: pages/ajax.render.php• L33-70

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the order of RequestParamDTO declarations aligned with the order of values unpacked from HandleRequestParam.
  • Keep sanitization filters matched to the semantic type of each input. A filter change can alter the value that business code receives without changing the endpoint signature.
  • Keep HttpBadRequestException catches at the endpoint boundary. If a catch is removed, a missing parameter can become a fatal response instead of the intended 400 response.
  • Keep AJAX checks after login when transaction-token validation is required.
  • Keep response content types aligned with the client that consumes the endpoint body.

Important failure modes

TriggerConsequenceGuard
A mandatory parameter is absentThe request gets status 400 and the endpoint action does not run.Declare the parameter as mandatory and handle HttpBadRequestException at the endpoint boundary.
An AJAX POST lacks the required header and a valid transaction tokenThe request is treated as unauthorized and gets status 401.Call CheckAjaxEndpoint after login and send the unauthorized response on SecurityException.
Values are unpacked in a different order from their declarationsAn action can use one input as another input.Preserve declaration and unpacking order.
A response body uses the wrong content typeThe client can fail to parse or render a valid body.Use the JSON helper for structured data and the plain-text helper for text outcomes.

Key files

FileWhy to read it
sources/…/HttpRequest.phpDefines parameter extraction, required-input failure, and AJAX request checks.
sources/…/RequestParamDTO.phpDefines the input contract that endpoint code declares.
sources/…/HttpBadRequestException.phpDefines the exception used to carry invalid input to the endpoint boundary.
sources/…/HttpResponse.phpDefines status, content type, body, and termination behavior for common outcomes.
datamodels/…/ajax.itop-attachment.phpShows a complete endpoint that declares inputs and maps security, bad-request, and fatal failures to responses.
pages/ajax.render.phpShows the shared legacy AJAX boundary using the request security and response helpers.