Incorrect HTTP response with status 200 and empty body


I’m trying to write a library to interact with the Jetbrains Space HTTP API, but have been running into some problems. When submitting an HTTP request to their API, I always get back a 200 OK status, even though this is not actually the case.

This is the request I send to the server.

POST /api/http/projects HTTP/1.1
User-Agent: Go-http-client/1.1
Content-Length: 78
Authorization: Bearer  <oauth2 access token>
Accept-Encoding: gzip
Accept: application/json


Using the following code:

    buf := bytes.NewBuffer(nil)
	_ = json.NewEncoder(buf).Encode(map[string]interface{}{
		"key": map[string]interface{}{"key": "ABC"},
		"name": "Test",
		"private": true,
		"description": "",
		"tags": []string{},

	req, err := http.NewRequest("POST", "", buf)
	if err != nil {
	req.Header.Set("Authorization", "Bearer <oauth2 access token>")
    req.Header.Set("Accept", "application/json")

	resp, err := http.DefaultClient.Do(req)
	if err != nil {

What I’m expecting to see is a 403 Forbidden status, with the following error message:

{"error":"permission-denied","error_description":"Only users are allowed to perform this operation"}

But this is what I end up getting:

HTTP/2.0 200 OK
Content-Length: 0
Date: Sat, 23 May 2020 10:13:21 GMT
Vary: Origin

I only ever seem to be getting 200 OK with no body data for these errors with the Go HTTP client. I have tried the same request from Javascript, which seemed to work fine, which leads me to believe it’s some quirk with the Go HTTP client.

This same problem occurs with different endpoints, but curiously enough it works correctly if the call to the endpoint is successful. (An actual 200 OK)

Does anyone have any pointers for me?

Thank you for any help you can offer.

So as it turns out, there was a missing header which caused the endpoints to return 200 OK without a body. Apparently this header was present automatically in the Javascript library I used.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.