Skip to content

Commit

Permalink
Fix #7
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelreyna committed Jul 15, 2020
1 parent 0b52798 commit 027dd07
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 1 addition & 2 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ See also: --tls-cert ; -T, --ss-tls`,

RootCmd.Flags().StringVarP(&username, "username", "U", "", `Username for basic authentication.
If an empty username ("") is set then a random, easy to remember username will be used.
If a password is not also provided using either the -P, --password flag , then the client may enter any password;
-W, --hidden-password; or -w, --password-file flags then the client may enter any password.`,
If a password is not also provided using either the -P, --password flag ; -W, --hidden-password; or -w, --password-file flags then the client may enter any password.`,
)

RootCmd.Flags().StringVarP(&password, "password", "P", "", `Password for basic authentication.
Expand Down
18 changes: 18 additions & 0 deletions internal/handlers/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import (
"io"
"log"
"net/http"
"strings"
"time"

"github.com/raphaelreyna/oneshot/internal/file"
"github.com/raphaelreyna/oneshot/pkg/server"
)

func HandleDownload(file *file.FileReader, download bool, header http.Header,
Expand Down Expand Up @@ -85,6 +87,22 @@ func HandleDownload(file *file.FileReader, download bool, header http.Header,
}

return func(w http.ResponseWriter, r *http.Request) error {
// Filter out requests from bots, iMessage, etc.
if headers, exists := r.Header["User-Agent"]; exists {
for _, header := range headers {
isBot := strings.Contains(header, "bot")
if !isBot {
isBot = strings.Contains(header, "Bot")
}
if !isBot {
isBot = strings.Contains(header, "facebookexternalhit")
}
if isBot {
w.WriteHeader(http.StatusOK)
return server.OKNotDoneErr
}
}
}
iLog("connected: %s", r.RemoteAddr)
err := file.Open()
defer func() {
Expand Down
1 change: 0 additions & 1 deletion pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func NewServer() *Server {
finishedRoutes: make(map[*Route]error),
}
s.server = &http.Server{Handler: s}

return s
}

Expand Down

0 comments on commit 027dd07

Please sign in to comment.