Skip to content

Request logging silently discarded for non-JSON/form-encoded entity types #1322

Open

Description

@mhagnumdw

Description

When calling MergeRequestApi.acceptMergeRequest(projectId, mrIid), the HTTP request line and headers are not logged, even though the response is logged normally.

Root cause

In MaskingLoggingFilter.aroundWriteTo(), there's a conditional check that only logs when the media type is application/json or application/x-www-form-urlencoded:

if (mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE)
|| mediaType.isCompatible(MediaType.APPLICATION_FORM_URLENCODED_TYPE)) {
log(stream.getStringBuilder(MessageUtils.getCharset(mediaType)));
}

For text/plain the request line and headers accumulated in the StringBuilder are discarded.

Expected Log (should show PUT request)

11:57:55,027 INFO [train-processor-1] 1 - Sending client request on thread train-processor-1
1 > PUT http://localhost:8929/api/v4/projects/1/merge_requests/2/merge
1 > Accept: application/json
1 > Content-Type: text/plain
1 > PRIVATE-TOKEN: ********

11:57:55,188 INFO [train-processor-1] 1 - Received server response on thread train-processor-1
1 < 422
1 < Cache-Control: no-cache
1 < Content-Length: 37
1 < Content-Type: application/json
...

Current Behavior (request missing)

Only the response is logged; the request line and headers are lost.

Question

Why does the if condition in aroundWriteTo() restrict logging only to JSON and form-urlencoded? Without this check, the request logs appear correctly. I've already run some tests without that if statement and everything seems okay.

Activity

  1. jmini commented on May 12, 2026

    @jmini
    Collaborator

    I am wondering why MergeRequestApi.acceptMergeRequest(projectId, mrIid) is sending a text/plain request. Does it makes sense?

    From my observation the GitLab server supports many ways to express request parameters. You can pass parameters as string query parameter or as Json request body. I have noticed many inconsistency in the GitLab4j client.

    We we decide to keep text/plain, probably the mentioned class MaskingLoggingFilter.java should be modified.

    It needs more investigations

  2. mhagnumdw commented on May 12, 2026

    @mhagnumdw
    ContributorAuthor

    I am wondering why MergeRequestApi.acceptMergeRequest(projectId, mrIid) is sending a text/plain request. Does it makes sense?

    It's sending text/plain because of line 750 below.

    protected Response put(MultivaluedMap<String, String> queryParams, URL url) {
    if (queryParams == null || queryParams.isEmpty()) {
    Entity<?> empty = Entity.text("");
    return (invocation(url, null).put(empty));
    } else {
    return (invocation(url, null).put(Entity.entity(queryParams, MediaType.APPLICATION_FORM_URLENCODED_TYPE)));
    }
    }

    It's assumed that if there are no queryParams (entity data) it will always be text/plain. I don't know if this is valid for all endpoints that don't require a payload body.

    Official GitLab documentation about Request payload: https://docs.gitlab.com/18.11/api/rest/#request-payload

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions