I want to store a whole HTTP response in PostgreSQL database row.
I need the HTTP status, the headers and the body.
AFAIK there is no native data type for this.
How could I store a HTTP response?
Update
I have been thinking about this again. I guess it is best if I follow this pattern: I won't search anything inside the http response. It is like a blob. Everything I want to search in it while be extracted before and put into a different column. Up to now only the http status code will get used and it will get an own column.
Best Answer
The HTTP/1.1 spec says, through RFC-7230, that:
int4
orint2
would do.for the entire header, see 3.2.4, "Field parsing":
"opaque" pretty much implies that
bytea
is the only safe choice, if you want to handle the responses of any HTTP server out there.The message body is defined as
message-body = *OCTET
, sobytea
is also pretty much the only type that fits, unless you prefer the large objects storage and API.bytea
is limited to 1Gb so you may want to chunk the value across several smaller rows if you target any size. In practice, very large bytea values tend to be unworkable, personally I wouldn't go over 128Mb per row.