Skip to content

ctx.Status() does not affect httptest.ResponseRecorder while ctx.JSON() does #4071

Description

@cardillomarcelo

Description

ctx.Status() does not affect httptest.ResponseRecorder while ctx.JSON() does

How to reproduce

package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"net/http"
	"net/http/httptest"
	"testing"
)

func TestName(t *testing.T) {
	recorder := httptest.NewRecorder()

	c, _ := gin.CreateTestContext(recorder)

	changeResponseCode(c)

	fmt.Println(recorder.Code)
}

func changeResponseCode(ctx *gin.Context) {
	ctx.Status(http.StatusNoContent)
}

Expectations

Should print 204

Actual result

Prints 200

Environment

  • go version: 1.23.2
  • gin version (or commit ref): 1.10.0
  • operating system: Ubuntu 22.04

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions