mscdex / busboy

A streaming parser for HTML form data for node.js
MIT License
2.84k stars 213 forks source link

need to get raw headers #345

Open jimmywarting opened 11 months ago

jimmywarting commented 11 months ago

I need to get the full raw headers from each field, as is, without any modification.

Motivation

You do strip out quite a bit, and leave many things behind.

headers that are not known to you gets discarded, headers meta ;key=value pair gets discarded too.

And some things even get modified as you apply to lowercase here and there.

I need to parse the headers on my own, so it would be good if you could send the headers as a 2D iterable array (as one header could appair twice)

// x-forwared-for: 192.168.0.1
// x-forwared-for: 192.168.0.2

headers = new Headers([
  ['x-forwared-for', '192.168.0.1'],
  ['x-forwared-for', '192.168.0.2']
])
headers.get('x-forwared-for') // 192.168.0.1, 192.168.0.2

Example

the arguments length is getting out of control cuz they are so many now. and i don't need all of them... An object would be better...

-   busboy.on('field', (fieldname, val, fieldnameTruncated, valTruncated, encoding, mimetype) => {
+   busboy.on('field', (field) => {
      console.log(`Field [${field.fieldname}]: value: ${field.val}`);
    });

so that i could do:

busboy.on('field', (field) => {
  console.assert(Array.isArray(field.headers))
  Object.fromEntries(field.headers)
  new Headers(field.headers)
})
mscdex commented 11 months ago

An object would be better...

I take it you haven't upgraded to v1.x?