2020-09-16 20:07:28 +08:00
|
|
|
// This is a buffering parser, not quite as nice as the multipart one.
|
|
|
|
// If I find time I'll rewrite this to be fully streaming as well
|
2023-10-26 19:02:46 +08:00
|
|
|
import { parse } from 'node:querystring'
|
2020-09-16 20:07:28 +08:00
|
|
|
|
|
|
|
export class QuerystringParser {
|
|
|
|
constructor(maxKeys) {
|
|
|
|
this.maxKeys = maxKeys
|
|
|
|
this.buffer = ''
|
|
|
|
}
|
|
|
|
|
|
|
|
write(buffer) {
|
|
|
|
this.buffer += buffer.toString('ascii')
|
|
|
|
return buffer.length
|
|
|
|
}
|
|
|
|
|
|
|
|
end() {
|
2023-10-25 18:45:16 +08:00
|
|
|
var fields = parse(this.buffer, '&', '=', {
|
2020-09-16 20:07:28 +08:00
|
|
|
maxKeys: this.maxKeys
|
|
|
|
})
|
|
|
|
for (var field in fields) {
|
|
|
|
this.onField(field, fields[field])
|
|
|
|
}
|
|
|
|
this.buffer = ''
|
|
|
|
|
|
|
|
this.onEnd()
|
|
|
|
}
|
|
|
|
}
|