tarantool / tarantool/http

Request string reprenetations prints non-existing field

Open
#193 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug question
Dominant language
Lua
Stars
81
Forks
41
PR merge metrics
No merged PRs in 30d

Description

tostring(req) invokes request_tostring function, which does the following step:
https://github.com/tarantool/http/blob/6be78efcb2848d740b5c1c16511953a05b328e82/http/server.lua#L170

But request does not have a body attribute. response does. String representation of a request always ends with empty lines since .body == nil.

local log = require('log')

local http_server = require('http.server')

box.cfg{}

local httpd = http_server.new('127.0.0.1', 8081)
httpd:route(
    { path = '/hello', method = 'POST' }, function(req)
        local _ = req:json() -- If removed, result is the same.
        log.info(req.body)
        log.info(tostring(req))
        return req:render{text = 'OK'}
    end)
httpd:start()
curl -X POST localhost:8081/hello?a=a -d '{"sdfs":"dfdfsfs"}'
2023-09-18 10:31:12.506 [1212600] main/114/http/127.0.0.1:60846/http.server I> POST /hello?a=a
2023-09-18 10:31:12.506 [1212600] main/114/http/127.0.0.1:60846/. I> 
2023-09-18 10:31:12.506 [1212600] main/114/http/127.0.0.1:60846/. I> POST /hello?a=a HTTP/1.1
Host: localhost:8081
Content-type: application/x-www-form-urlencoded
Content-length: 18
Accept: */*
User-agent: curl/7.81.0


Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The request_tostring function is at http/server.lua#L170; read that implementation and compare the request fields with the response fields described in the issue. Reproduce the shown POST route with the provided curl command, then verify that tostring(req) no longer includes the nonexistent body or trailing empty lines.

Written by the indexing model from the issue text.

Assessment

Tech stack
lua
Domain
backend
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.