sdstoehr / har-reader

Library for accessing HTTP Archives (HAR) with Java
MIT License
91 stars 30 forks source link

HarReaderException if cookies' expires with weird format #6

Closed kristian-lange closed 9 years ago

kristian-lange commented 9 years ago

Sometimes cookies' expires value is in a weird format, e.g. I get on a webpage

"response": {
      "status": 302,
      "statusText": "Found",
      "httpVersion": "HTTP/1.1",
      "cookies": [
        {
          "name": "ExciteGermany",
          "value": "1",
          "path": "/",
          "expires": "NaN-NaN-NaNTNaN:NaN:NaN.NaN+NaN:NaN",
          "domain": ".populisengage.com"
        },

Unfortunately har-reader throws an exception in theses cases: de.sstoehr.harreader.HarReaderException: com.fasterxml.jackson.databind.exc.InvalidFormatException: Can not construct instance of java.util.Date from String value 'NaN-NaN- NaNTNaN:NaN:NaN.NaN+NaN:NaN': not a valid representation (error: Failed to parse Date value 'NaN-NaN-NaNTNaN:NaN:NaN.NaN+NaN:NaN': Can not parse date "NaN-NaN-NaNTNaN:NaN:NaN.NaN+NaN:NaN": not compatible with any of standard forms ("yyyy-MM-dd'T'HH:mm:ss.SSSZ", "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'", "EEE, dd MMM yyyy HH:mm:ss zzz", "yyyy-MM-dd"))

Is it possible to let har-reader just ignore weirdly formated expires values?

maxbraun commented 9 years ago

-1

kristian-lange commented 9 years ago

Any explanation for your '-1'? Maybe it's just plain stupid, but I just can't see it.

maxbraun commented 9 years ago

From my point of view the har-reader works correct. Maybe the writer of the shouldn't write NaNs. Which piece of software do you use to write the Har?

kristian-lange commented 9 years ago

Sorry, I didn't want to imply your software works incorrectly.

The problem here is just that these NaNs happen in the wild and we can't change it. It might not be how your and mine definition of good data or code is but they are there.

I'm using Firebug and NetExport.

maxbraun commented 9 years ago

Maybe Sebastian will merge my PullRequest. This could solve our Problem.

kristian-lange commented 9 years ago

Thank you!

sdstoehr commented 9 years ago

I've released version 1.1.0 - it may take some time, until it is synced to maven central.

Now you are able to set a "lax mode" and ignore invalid date fields:

Har har = HarReader.fromFile(harFile, HarReaderMode.LAX); // Lax mode -> ignoring invalid date formats
Har har = HarReader.fromFile(harFile); // Strict mode / old behaviour

Thanks to @maxbraun for the implementation!

Regards, Sebastian

kristian-lange commented 9 years ago

It's working like a charm!