Skip to content

Commit a60f403

Browse files
Hexawolffoxcpp
authored andcommitted
Support HEAD and fix broken dependency (#13)
* Handle HEAD * Fix broken UUID package * Add sanity check for HEAD and GET requests * [skip ci] Remove go version from go.mod
1 parent 30f4f9b commit a60f403

File tree

5 files changed

+40
-5
lines changed

5 files changed

+40
-5
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
coverage.txt
2+
.idea/
3+
*.db
4+
*.exe
5+
filedropd.yml

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/foxcpp/filedrop
22

33
require (
44
github.com/go-sql-driver/mysql v1.4.0
5-
github.com/gofrs/uuid/v3 v3.1.1
5+
github.com/gofrs/uuid v3.2.0+incompatible
66
github.com/lib/pq v1.0.0
77
github.com/mattn/go-sqlite3 v1.9.0
88
github.com/pkg/errors v0.8.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
github.com/go-sql-driver/mysql v1.4.0 h1:7LxgVwFb2hIQtMm87NdgAVfXjnt4OePseqT1tKx+opk=
22
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
3-
github.com/gofrs/uuid/v3 v3.1.1 h1:sqMK0jjyOJ7HV36lwG2GZ6TD2hK8RB7dJQVDakI65U4=
4-
github.com/gofrs/uuid/v3 v3.1.1/go.mod h1:xPwMqoocQ1L5G6pXX5BcE7N5jlzn2o19oqAKxwZW/kI=
3+
github.com/gofrs/uuid v3.2.0+incompatible h1:y12jRkkFxsd7GpqdSZ+/KCs/fJbqpEXSGd4+jfEaewE=
4+
github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
55
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
66
github.com/lib/pq v1.0.0 h1:X5PMW56eZitiTeO7tKzZxFCSpbFZJtkMMooicw2us9A=
77
github.com/lib/pq v1.0.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=

server.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"strings"
1414
"time"
1515

16-
"github.com/gofrs/uuid/v3"
16+
"github.com/gofrs/uuid"
1717
"github.com/pkg/errors"
1818
)
1919

@@ -347,7 +347,7 @@ func (s *Server) serveFile(w http.ResponseWriter, r *http.Request) {
347347
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
348348
if r.Method == http.MethodPost {
349349
s.acceptFile(w, r)
350-
} else if r.Method == http.MethodGet {
350+
} else if r.Method == http.MethodGet || r.Method == http.MethodHead {
351351
s.serveFile(w, r)
352352
} else {
353353
w.WriteHeader(http.StatusMethodNotAllowed)

server_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"net/http/httptest"
99
"os"
1010
"path/filepath"
11+
"reflect"
1112
"strings"
1213
"testing"
1314
"time"
@@ -38,6 +39,36 @@ func TestBasicSubmit(t *testing.T) {
3839
}
3940
}
4041

42+
func TestHeadAndGet(t *testing.T) {
43+
serv := initServ(filedrop.Default)
44+
ts := httptest.NewServer(serv)
45+
defer cleanServ(serv)
46+
defer ts.Close()
47+
c := ts.Client()
48+
49+
url := string(doPOST(t, c, ts.URL+"/filedrop", "text/plain", strings.NewReader(file)))
50+
51+
t.Log("File URL:", url)
52+
53+
respHead, err := c.Head(url)
54+
if err != nil {
55+
t.Error("GET:", err)
56+
t.FailNow()
57+
}
58+
respGet, err := c.Get(url)
59+
if err != nil {
60+
t.Error("HEAD:", err)
61+
t.FailNow()
62+
}
63+
defer respHead.Body.Close()
64+
defer respGet.Body.Close()
65+
66+
if !reflect.DeepEqual(respHead.Header, respGet.Header) {
67+
t.Error("Headers are different!")
68+
t.FailNow()
69+
}
70+
}
71+
4172
func TestFakeFilename(t *testing.T) {
4273
conf := filedrop.Default
4374
serv := initServ(conf)

0 commit comments

Comments
 (0)