The problem with that approach is that you lose the original request string--which may be important in some cases. (no pun intended ;-)
I wonder if we should take this opportunity to provide a more user
friendly way to access headers, with a new interface. People seem to
find the required use of >+ and >+> pretty confusing, and awkward even
after they understand how it works.
Nathan
yes, it is quite complicated. I got it to function right now, after quite a bit of work though. Part of the problem was IntelliJ perhaps not getting the syntax right. So I had to write out the types carefully. Here's my first use:
def get() = {
// note we prefer rdf/xml and turtle over html, as html does not always contain rdfa, and we prefer those over n3,
// as we don't have a full n3 parser. Better would be to have a list of available parsers for whatever rdf framework is
// installed (some claim to do n3 when they only really do turtle)
// we can't currently accept */* as we don't have GRDDL implemented
val request = url(u.toString) <:< Map("Accept"->
"application/rdf+xml,text/turtle,application/xhtml+xml;q=0.8,text/html;q=0.7,text/n3;q=0.6")
//we need to tell the model about the content type
val handler: Handler[Validation[Throwable, Model]] = request.>+>[Validation[Throwable, Model]](res => {
res >:> { headers =>
val encoding = headers("Content-Type").headOption match {
case Some(mime) => RDFEncoding(mime)
case None => RDFXML // it would be better to try to do a bit of guessing in this case by looking at content
}
val loc = headers("Content-Location").headOption match {
case Some(loc) => new URL(u,loc)
case None => new URL(u.getProtocol,u.getAuthority,u.getPort,u.getPath)
}
res>>{ in=>modelFromInputStream(in,loc.toString,encoding) }
}
})
http(handler)
}
What I wonder is if there is no way to somehow make it work with the Unfiltered header objects. Somehow it seems one feels like the pattern matching on headers should work here too...
Henry
>
> Nathan
That's a neat idea. It would be tempting (and tricky) to share the code,
but there is not actually that much to share because Unfiltered is
concerned with extracting request headers. For response headers it has
response functions, which won't do us any good. But we could certainly
copy the idea and supply a slew of response header extractors.
Nathan
The problem with that approach is that you lose the original request string--which may be important in some cases. (no pun intended ;-)