wdio-intercept-service icon indicating copy to clipboard operation
wdio-intercept-service copied to clipboard

HTTP header parsing is fundamentally wrong (in parseResponseHeaders)

Open jbebe opened this issue 3 years ago • 5 comments

wdio-intercept-service version 4.2.1

This is the header parser:

arr.forEach((header) => {
  const match = header.match(/^(.+)?:\s?(.+)$/);
  if (match) {
    headers[match[1].toLowerCase()] = match[2];
  }
});

This is the parsed header output for a simple server response:

{
  "access-control-allow-origin: https": "//google.com/"
  "content-security-policy: default-src 'self' https": "//google.com"
  "date: wed, 23 feb 2022 14:09": "06 GMT"
  "etag: '05a73f427d81": "'0'"
  "last-modified: mon, 21 feb 2022 09:19": "00 GMT"
}

This lib should help you lift the burden of parsing headers: parse-headers

jbebe avatar Feb 23 '22 14:02 jbebe

PRs are very welcome :)

Thanks for reporting, it was definitely not a good idea to attempt that from the hip there.

chmanie avatar Feb 24 '22 19:02 chmanie

I don't have the authority to decide if you can use one more lib. But if you say it's allowed, sure, I create a PR with that npm package.

jbebe avatar Feb 24 '22 19:02 jbebe

It's definitely allowed :heart:. My approach was only good for some cases, I'm actually surprised that it didn't blow up much earlier

chmanie avatar Feb 24 '22 19:02 chmanie

I'm actually surprised that it didn't blow up much earlier

That was my thought, too. Alright. I'll be back with a PR tomorrow.

jbebe avatar Feb 24 '22 20:02 jbebe

@christian-bromann this issue can also be closed with the release of 4.3.0

tehhowch avatar Sep 08 '22 09:09 tehhowch

Closed in #241

tehhowch avatar Dec 21 '22 13:12 tehhowch