Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added dynamic endstream #96

Merged
merged 2 commits into from
Aug 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/http2/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class Http2Request extends EventEmitter {
return this.stream.write(chunk)
}

_flushHeaders () {
_flushHeaders (endStream = false) {
if (this[kHeadersFlushed]) {
throw new Error('Headers already flushed')
}
Expand All @@ -174,7 +174,7 @@ class Http2Request extends EventEmitter {
.filter(([key]) => !connectionHeaders.includes(key.toLowerCase()))
)

this.stream = this._client.request(this.requestHeaders, { endStream: false })
this.stream = this._client.request(this.requestHeaders, {endStream})

this.registerListeners()

Expand Down Expand Up @@ -210,7 +210,7 @@ class Http2Request extends EventEmitter {

end () {
if (!this[kHeadersFlushed]) {
this._flushHeaders()
this._flushHeaders(true)
}
this.stream.end()

Expand Down Expand Up @@ -317,7 +317,7 @@ class ResponseProxy extends EventEmitter {
}

get headers () {
return this.response
return Object.fromEntries(Object.entries(this.response))
}

pause () {
Expand Down
4 changes: 4 additions & 0 deletions request.js
Original file line number Diff line number Diff line change
Expand Up @@ -2008,6 +2008,10 @@ Request.prototype.end = function (chunk) {
// Reference to request, so if _reqResInfo is updated (in case of redirects), we still can update the headers
const request = self._reqResInfo.request
Promise.resolve(self.req._header).then(function (header) {
if (!header) {
request.headers = []
return
}
request.headers = parseRequestHeaders(header)
})
}
Expand Down
63 changes: 63 additions & 0 deletions tests/test-body-http2.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,69 @@ addTest('testPutMultipartPostambleCRLF', {
]
})

tape('test Delete Request', function (t) {
s.on('/', function (req, res) {
req.pipe(res)
})

request(
{
uri: 'https://localhost:' + s.port,
method: 'DELETE',
strictSSL: false,
protocolVersion: 'http2',
body: 'test-data'
},
function (err, res, body) {
t.error(err) // defaults to 'application/octet-stream' content-type
t.equal(res.statusCode, 200)
t.equal(body.toString(), 'test-data')
s.removeAllListeners('/')
t.end()
}
)
})

tape('test HEAD Request', function (t) {
request(
{
uri: 'https://github.com',
method: 'HEAD',
strictSSL: false,
protocolVersion: 'http2',
body: 'test-data'
},
function (err, res, body) {
t.error(err)
t.equal(res.statusCode, 400)
t.end()
}
)
})

tape('test GET Request with body', function (t) {
s.on('/', function (req, res) {
req.pipe(res)
})

request(
{
uri: 'https://localhost:' + s.port,
method: 'GET',
strictSSL: false,
protocolVersion: 'http2',
body: 'test-data'
},
function (err, res, body) {
t.error(err)
t.equal(res.statusCode, 200)
t.equal(body.toString(), 'test-data')
s.removeAllListeners('/')
t.end()
}
)
})

tape('testBinaryFile', function (t) {
s.on('/', function (req, res) {
req.pipe(res)
Expand Down
Loading