Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read response headers #30

Open
hdgarrood opened this issue Jul 10, 2015 · 6 comments
Open

Read response headers #30

hdgarrood opened this issue Jul 10, 2015 · 6 comments
Assignees
Labels
type: enhancement A new feature or addition.

Comments

@hdgarrood
Copy link
Contributor

I'd like to be able to do things like ask if a response has a certain header, or get the value of a certain header in the response (if it exists).

Currently it seems impossible to do this, since the ResponseHeader data type doesn't export its constructor, and I don't see any functions for extracting this information from them.

@hdgarrood
Copy link
Contributor Author

Oh - having seen RequestHeader, I suppose the motivation is to avoid a stringly-typed interface?

Would it be possible to expose some way of getting everything as just strings, possibly with a note in the documentation suggesting people use the stronger typed interface instead?

@garyb
Copy link
Member

garyb commented Jul 10, 2015

Yeah, exactly. Both types need work actually to be extended with common cases, but we could definitely do something to expose them as strings too - responseHeaderName :: ResponseHeader -> String, responseHeaderValue :: ResponseHeader -> String like there is for requestHeaderName. Would that do it?

@garyb garyb self-assigned this Jul 10, 2015
@garyb garyb added the type: enhancement A new feature or addition. label Jul 10, 2015
@hdgarrood
Copy link
Contributor Author

Yeah I think so - then presumably I could do something like response.headers # Data.Foldable.find (responseHeaderName >>> eq "Set-Cookie") # map responseHeaderValue to get the header value as a Just if it's there, and Nothing otherwise?

Also perhaps a newtype wrapper around String which makes equality and comparison case insensitive might be helpful here?

@garyb
Copy link
Member

garyb commented Jul 10, 2015

Yep, that's along the lines of what I was thinking. Case insensitive newtype for String comparisons sounds good too, would make a nice addition to purescript-strings.

@paf31
Copy link

paf31 commented Jul 10, 2015

@garyb
Copy link
Member

garyb commented Jul 10, 2015

Ok, I've added those functions now. Although on further reflection neither responseHeaderValue or requestHeaderValue are quite right in the long run, there should probably be a phantom type on ResponseHeader and RequestHeader that determines their contained content type.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A new feature or addition.
Development

No branches or pull requests

3 participants