Questions tagged [haskell-wai]

The wai package provides a common protocol for the communication between Haskell web applications and web servers.

The wai package provides a common protocol for the communication between Haskell web applications and web servers.

GitHub Repo: https://github.com/yesodweb/wai

Source: http://hackage.haskell.org/package/wai

73 questions
4
votes
2 answers

Thread-safe state with Warp/WAI

I want to write a web server which stores its state in a State monad with wai/warp. Something like this: {-# LANGUAGE OverloadedStrings #-} import Network.Wai import Network.Wai.Handler.Warp import Network.HTTP.Types import…
nponeccop
  • 13,527
  • 1
  • 44
  • 106
3
votes
2 answers

How to access raw request body in servant application

In a servant/wai application the request body can be obtained using a combinator e.g. ReqBody '[JSON] Book. In this case the body is extracted as a value of type Book. It is not clear how the raw request body can be accessed without converting it to…
7puns
  • 1,505
  • 1
  • 9
  • 9
3
votes
1 answer

Serving a yesod application as a (Fast)CGI

I'm trying to serve a yesod application as a CGI (or FastCGI) program but Apache shows me a 500 error: [Mon Sep 21 17:35:41.425565 2020] [http:error] [pid 2758] [client 10.0.2.2:43872] AH02429: Response header name '21/Sep/2020' contains invalid…
3
votes
1 answer

Middleware that puts data in the request vault

I'm trying to write a WAI middleware that puts some data in the request's vault, but it seems I'm missing something because I can't look it up later. Even the simplest middleware fail: fooMW :: Middleware fooMW app req sendResponse = do k <-…
Magnus
  • 4,644
  • 1
  • 33
  • 49
3
votes
0 answers

How to add a specific representation of the request and response of the body of an HTTP request with Haskell Middleware

How can i add a specific representation of the request and response body in a request logger? I would like to be able to have some typeclass that allows me to achieve this representation. In the Network.Wai.Middleware.RequestLogger.JSON I can see…
emg184
  • 850
  • 8
  • 19
3
votes
0 answers

Interleaving WAI streaming with safe-pipes

I'm using pipes and WAI to stream audio. The problem is that I need to lookahead some data in safe-pipe, then choose response headers based on extracted information, and then continue streaming that pipe as the response body. Here is what I have now…
aemxdp
  • 1,348
  • 1
  • 14
  • 34
3
votes
1 answer

Using Request Parameters in WAI Without "IO" Causing Problems

I'm struggling with the basics of getting an API up and running using WAI. The main issue is dealing with IO infecting everything. I believe that my problems will dissolve once I better understand Monads, but hopefully an answer to this question…
user3594595
3
votes
1 answer

In Haskell WAI, how do I add headers as Middleware?

I am trying to understand Middleware by writing a very simple session manager. I need to add the SetCookie header in the response. I've looked at the wai-extra package, and found wai-session. I'm using wai-3.0.2, which doesn't seem to give me…
rob
  • 2,053
  • 15
  • 13
3
votes
1 answer

Fibonacci web service with WAI

I'm trying to write a simple Fibonacci web server using WAI but I just can't figure out the types. This code is the essence of what I want to do, but it's broken. The getQueryArg function returns a Maybe ByteString and I want to use that in my…
Sam
  • 2,620
  • 2
  • 26
  • 28
3
votes
1 answer

Unexpected conduit behaviour with wai

I'm trying to write a really trivial "echo" webapp using wai; all I want it to do is reply with the data that is POSTed to it (I really don't care about the method, but I'm using curl and curl is using POST, so that's what I'm going for). My…
tsuraan
  • 240
  • 1
  • 3
2
votes
1 answer

How to run an action after response has been fully sent in Scotty / WAI

Upon a GET request, my Scotty webapp will run some computation and store its result in a temporary file, which it sends as the response using file. Now I would like to run some cleanup (i.e. delete the temporary file) after the file has been sent.…
2
votes
0 answers

Trouble working with `requestBody` (or `getRequestBodyChunk`)

Dependency versions Wai: 3.2.2.1 Synopsis The working of getRequestBodyChunk (https://hackage.haskell.org/package/wai-3.2.2.1/docs/Network-Wai.html#v:getRequestBodyChunk) is quite unclear to me. I understand that it reads the next chunk of bytes…
Ashesh
  • 2,978
  • 4
  • 27
  • 47
2
votes
2 answers

Streaming bytestring as WAI HTTP server response body

I have a value body :: BS.ByteString (ResourceT IO) (), from a function based on BS.readFile. I want to stream that value as the response body from a Wai Application. There's a helper, streamingResponse that takes a value of the type Stream (Of…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
2
votes
2 answers

Handling POST request in Wai/Warp in Haskell

I have a wai/warp application. How can I handle a post request? I have this: app :: Application app request respond = respond $ case rawPathInfo request of "/" -> responseFile status200 ............ "/some_post_req/" ->…
Otoma
  • 161
  • 2
  • 11
2
votes
1 answer

Join two Network.Wai.Application

i am using servant and Network.Wai.Application.Static for json api and static file serving respectively. I want to join these two Application such that if staticApp fails to serve, request should go to jsonApp. I tried finding out and read how…
Ashish Negi
  • 5,193
  • 8
  • 51
  • 95