unirakun / k-ramel

State manager for your components apps, the safe and easy way
MIT License
21 stars 5 forks source link

Get the header of the HTTP response #281

Closed jeromemenard closed 5 years ago

jeromemenard commented 5 years ago

Hello. Can we get the header of the HTTP response with the driver '@k-ramel/driver-http driver'?

fabienjuif commented 5 years ago

I will add a headers field in the action dispatched by ENDED and FAILED.

From here I have 2 options to serialize the headerss

Option 1: Object

{
  connection: "close"
  "content-length": "393"
  "content-type": "application/json; charset=utf-8"
  date: "Mon, 14 Jan 2019 10:31:00 GMT"
​  vary: "Accept-Encoding"
​  "x-powered-by": "Express"
}

You can access header by: action.headers["x-powered-by"]

Option 2: Arrays (Map)

[
  [
    "connection",
    "close"
  ],
  [
    "content-length",
    "393"
  ],
  [
    "content-type",
    "application/json; charset=utf-8"
  ],
  [
    "date",
    "Mon, 14 Jan 2019 10:33:44 GMT"
  ],
  [
    "vary",
    "Accept-Encoding"
  ],
  [
    "x-powered-by",
    "Express"
  ]
]

You can access header by: new Map(action.headers).get("x-powered-by")

jeromemenard commented 5 years ago

I prefer option number 1 but let you choose the easiest option to implement. Thank you very much.

fabienjuif commented 5 years ago

Ok, I'll write option 1.

I think we'll publish a 1.3.0 version this evening.

fabienjuif commented 5 years ago

nevermind, I don't know about this evening, I have a breaking change in an other PR :( I'll keep you in touch @jeromemenard