-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathhttp.go
32 lines (27 loc) · 890 Bytes
/
http.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
// Copyright 2014 Google Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
package webmention
import (
"fmt"
"net/http"
"willnorris.com/go/webmention/third_party/header"
)
// ErrNoEndpointFound is returned when no endpoint can be found for a certain
// target URL.
var ErrNoEndpointFound = fmt.Errorf("no endpoint found")
// httpLink parses headers and returns the URL of the first link that contains
// a webmention rel value.
func httpLink(headers http.Header) (string, error) {
for _, h := range header.ParseList(headers, "Link") {
link := header.ParseLink(h)
for _, v := range link.Rel {
if v == relWebmention || v == relLegacy || v == relLegacySlash {
return link.Href, nil
}
}
}
return "", ErrNoEndpointFound
}