-
Notifications
You must be signed in to change notification settings - Fork 0
/
httphandler.go
79 lines (65 loc) · 1.63 KB
/
httphandler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package webfinger
import (
"net/http"
"net/url"
)
// HTTPHandler returns an http.Handler based on the passed 'webFingerHandler'.
//
// You can think of it as a way of turning a webfinger.Handler into an http.Handler.
func HTTPHandler(webFingerHandler Handler) http.Handler {
return internalHTTPHandler{
handler: webFingerHandler,
}
}
type internalHTTPHandler struct {
handler Handler
}
func (receiver internalHTTPHandler) ServeHTTP(responseWriter http.ResponseWriter, request *http.Request) {
if nil == responseWriter {
return
}
if nil == request {
httpError(responseWriter, http.StatusInternalServerError)
return
}
var handler Handler = receiver.handler
if nil == handler {
httpError(responseWriter, http.StatusInternalServerError)
return
}
var resource string
{
var httpRequestURL *url.URL = request.URL
if nil == httpRequestURL {
httpError(responseWriter, http.StatusInternalServerError)
return
}
var query url.Values = httpRequestURL.Query()
if nil == query {
httpError(responseWriter, http.StatusBadRequest)
return
}
var resources []string
var found bool
resources, found = query["resource"]
if !found {
httpError(responseWriter, http.StatusBadRequest)
return
}
if 1 != len(resources) {
httpError(responseWriter, http.StatusBadRequest)
return
}
resource = resources[0]
}
{
const contentType string = "application/jrd+json"
var header http.Header = responseWriter.Header()
if nil == header {
httpError(responseWriter, http.StatusInternalServerError)
return
}
header.Add("Content-Type", contentType)
}
handler.ServeWebFinger(responseWriter, resource)
}