2

I'm trying to create http request with custom header (with http-conduit-1.9.4 usage):

req <- parse "https://some_url"
let request = req { requestHeaders = [customHeader] }

And I don't understant what should be customHeader? I have tried

import Network.HTTP.Headers
let custom_header = mkHeader (HdrCustom "Some-Header") "Some-Value"

but an error occured

Couldn't match expected type `Network.HTTP.Types.Header.Header'
                with actual type `Header'
    In the expression: custom_header
    In the `requestHeaders' field of a record
    In the expression: req {requestHeaders = [custom_header]}

also I have tried just

let custom_header = ("Some-Header", "Some-Value")

and error

Couldn't match expected type `Network.HTTP.Types.Header.HeaderName'
                with actual type `[Char]'
    In the expression: "User-Agent"
    In the expression: ("User-Agent", "erthalion")
    In the `requestHeaders' field of a record

So, anybody knows what should be customHeader?

erthalion
  • 3,094
  • 2
  • 21
  • 28
  • The error tells that you need Header from `Network.HTTP.Types.Header` module and not from `Network.HTTP.Headers` – Ankur Jul 07 '13 at 08:08
  • I know - I can't understand how create Network.HTTP.Types.Header object, and why it's different from Network.HTTP.Headers.Header – erthalion Jul 07 '13 at 08:11

1 Answers1

2

http-conduit does not use the HTTP package at all, they are two different approaches entirely. If you look in the http-types documentation, you'll see that a Header is just a tuple of header name and value.

The only reason your custom_header didn't work is because you need to turn on the OverloadedStrings language extension.

Michael Snoyman
  • 31,100
  • 3
  • 48
  • 77