File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change 4
4
// If the URL does not support common formats, unfurlist falls back to looking at common HTML tags
5
5
// such as <title> and <meta name="description">.
6
6
//
7
- // The endpoint accepts GET requests with `content` as the main argument.
7
+ // The endpoint accepts GET and POST requests with `content` as the main argument.
8
8
// It then returns a JSON encoded list of URLs that were parsed.
9
9
//
10
10
// If an URL lacks an attribute (e.g. `image`) then this attribute will be omitted from the result.
@@ -125,10 +125,20 @@ func New(config *Config) http.Handler {
125
125
}
126
126
127
127
func (h * unfurlHandler ) ServeHTTP (w http.ResponseWriter , r * http.Request ) {
128
- qs := r .URL .Query ()
128
+ switch r .Method {
129
+ case http .MethodGet , http .MethodPost :
130
+ default :
131
+ w .Header ().Set ("Allow" , "GET, POST" )
132
+ http .Error (w , http .StatusText (http .StatusMethodNotAllowed ), http .StatusMethodNotAllowed )
133
+ return
134
+ }
135
+ if err := r .ParseForm (); err != nil {
136
+ http .Error (w , http .StatusText (http .StatusBadRequest ), http .StatusBadRequest )
137
+ return
138
+ }
129
139
130
- content := qs .Get ("content" )
131
- callback := qs .Get ("callback" )
140
+ content := r . Form .Get ("content" )
141
+ callback := r . Form .Get ("callback" )
132
142
133
143
if content == "" {
134
144
http .Error (w , "Bad request" , http .StatusBadRequest )
You can’t perform that action at this time.
0 commit comments