request/lib/urlencoded_parser.js

27 lines
477 B
JavaScript

/**
* {}
* @author yutent<yutent.io@gmail.com>
* @date 2023/10/27 12:14:05
*/
import { parse } from 'node:querystring'
import { EventEmitter } from 'node:events'
export class UrlencodedParser extends EventEmitter {
#buf = Buffer.from('')
write(buffer) {
this.#buf = Buffer.concat([this.#buf, buffer])
}
end() {
let data = this.#buf.toString()
let fields = parse(data)
this.#buf = null
this.emit('field', fields)
this.emit('end')
}
}
对Http的request进一步封装, 提供常用的API
JavaScript 100%