Extend convenience functions to take arbitrary headers#88
Extend convenience functions to take arbitrary headers#88buckie wants to merge 2 commits intoaesiniath:mainfrom
Conversation
…s we are stuck in enterprise land and need wierd headers Signed-off-by: buckie <wjmartino@gmail.com>
Signed-off-by: buckie <wjmartino@gmail.com>
|
Hi @buckie. Nice to see you. In general, I'm not keen on this for the same reason I'm not keen on #64 — I don't want to exponentially grow the size of the public API to cater for an ever growing list of custom use cases. Now, that said, what you're asking for (and what @kosmoskatten is asking for) is not unreasonable. So what I'd like to do is figure out an API that retains the simplicity (if I've earned that title) that http-streams has presently while supporting more complex uses. (ironically, httpie (https://github.com/jakubroztocil/httpie) has exactly the usability you're looking for: on the command line you can say $ http GET http://www.example.com/about X-Biscuit-Flavour:chocolate to set a header field; key=value does query string / form / JSON parameter submission, etc. It's pretty nice. The strongly typed.... Ahhhh. Maybe we leave Or maybe we just figure out a new API for this library entirely. AfC |
|
Hi, Currently I'm using a modified http-streams, and I think one of my basic needs can be boiled down to a slight modification of the connectSocket to enable modification of the (not yet connected) socket. The beginning of my modified function looks like: connectSocket :: Hostname -> Port -> (Socket -> IO Socket) -> IO Socket
connectSocket h1' p modify = do
is <- getAddrInfo (Just hints) (Just h1) (Just $ show p)
let addr = head is
let a = addrAddress addr
s <- modify =<< socket (addrFamily addr) Stream defaultProtocol
connect s a
return sThe other need I have is to manipulate the io-streams. But if the API is "open" enough to allow me to tailor my own openConnection like functions with the official version of the library I think it's sufficient. Currently I use something like: openByteCountedConnection :: Hostname -> Port -> IO ByteCountedConnection
openByteCountedConnection host port = do
sock <- connectSocket host port return
streams <- Streams.socketToStreams sock
(ins, inc) <- Streams.countInput (fst streams)
(outs, outc) <- Streams.countOutput (snd streams)
conn <- makeConnection (modifyHostname host port) (close sock)
outs ins
return (conn, inc, outc)Then, of course, I have my own withByteCountedConnection etc. So I think my needs can be implemented with very little impact in then http-streams. |
I'd like to extend the convenience functions to take arbitrary headers. This use case is motivated by an issue @cartazio & I ran into at work. I wanted to add a
--headerflag to a program we've written so that I could add some random header to hit an internal system's URL. As we were usinggetI needed to replace the convenience function with the more general solution http-streams provides. It would have been really handy to just be able to tack on an extra header name=value.Please let me know if you want anything further on the pull.
-Will