Skip to content

Can't access request._body in server.onrequest() #15

@austinfrey

Description

@austinfrey

I have a simple server and I need to access the request._body property. Unfortunately it always defaults to an empty string. The client does not have access to the response body either. My code snippets are below. Any help is appreciated.
Thanks

//server.js
const runtime = require('runtimejs')
const http = require('eshttp')

const server = new http.HttpServer()
const response = new HttpResponse(200, {'x-header': 'value'}, 'hello from the server')

server.onrequest = request => {
    console.log('request body', request._body) // prints 'request body: '
    request.respondWith(response)
}
server.listen(9000)

my client looks like this.

// client.js
const http = require('eshttp')
const HttpClient = http.HttpClient
const HttpRequest = http.HttpRequest

const client = new HttpClient('localhost', 9000)
const request = new HttpRequest('GET', '/', {'x-header': 'value'}, 'hello from the client')

client.request(request, (err res) => {
    if (err) console.log(err)
    console.log('response:', res._body) // prints 'response: undefined'
})

client.close()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions