alevy / simple

A minimal Haskell web-framework based on the WAI web server interface.
http://simple.cx
39 stars 10 forks source link

Content-Type: text/plain #7

Closed mietek closed 10 years ago

mietek commented 10 years ago

What is the right way to get text/plain output, instead of text/html? The following code does not work properly:

import Network.Wai.Handler.Warp
import System.Environment
import Web.Simple

app :: (Application -> IO ()) -> IO ()
app runner = do
    runner $ controllerApp () $ do
      routeTop $ respond $ ok "text/plain" "Hello, world!"

main :: IO ()
main = do
    env <- getEnvironment
    let port = maybe 3000 read $ lookup "PORT" env
    app (run port)

Resolving this question would help me add hello-simple to a growing collection of Haskell web application deployment examples.

alevy commented 10 years ago

Hrm... That is supposed to be correct. I copy pasted that code into a file and ran it (with -XOverloadedStrings), and it worked. Here is the output from curl -D /dev/stdout localhost:3000:

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Mon, 10 Nov 2014 16:44:19 GMT
Server: Warp/3.0.2.3
Content-Type: text/plain

Hello, world!

What are you getting? Could you cabal freeze your dependencies so i can try to reproduce with your exact environment?

Thanks!

mietek commented 10 years ago

I am getting:

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Mon, 10 Nov 2014 19:48:56 GMT
Server: Warp/3.0.2.3
Content-Type: text/html

Hello, world!

My dependencies are already frozen. In fact, if you have a Heroku account, you should be able to reproduce the problem within 30 seconds. Please look at hello-simple.

alevy commented 10 years ago

I think you may have forgotten to commit your changes before deploying or something. The code you referenced uses okHtml, not ok "text/plain" as in your example. I just pulled your code, made the change in your example and deployed to heroku and am getting the expected result:

$ curl -D /dev/stdout https://enigmatic-savannah-4828.herokuapp.com/
HTTP/1.1 200 OK
Connection: keep-alive
Transfer-Encoding: chunked
Date: Mon, 10 Nov 2014 20:56:24 GMT
Server: Warp/3.0.2.3
Content-Type: text/plain
Via: 1.1 vegur

Hello, world!

My fork of the code is here: https://github.com/alevy/hello-simple

mietek commented 10 years ago

My apologies! You are right.