Skip to content

Commit

Permalink
Added Cache-Control to fiberpow.sha256.min.js
Browse files Browse the repository at this point in the history
  • Loading branch information
witer33 committed Jun 25, 2023
1 parent b6c102d commit f1d3851
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
14 changes: 8 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"fmt"
"math/big"
"strconv"
"strings"
"time"

"github.com/gofiber/fiber/v2"
Expand Down Expand Up @@ -76,12 +77,6 @@ func New(config ...Config) fiber.Handler {

// Middleware handler.
return func(c *fiber.Ctx) error {
// Returns the sha256 JS framework if requested.
if c.Path() == "/sha256.min.js" {
c.Set(fiber.HeaderContentType, fiber.MIMETextJavaScriptCharsetUTF8)
return c.SendString(sha256Library)
}

// Handles Config.Filter.
if cfg.Filter != nil && cfg.Filter(c) {
return c.Next()
Expand Down Expand Up @@ -135,6 +130,13 @@ func New(config ...Config) fiber.Handler {
return c.Next()
}

// Returns the sha256 JS library if requested.
if strings.HasSuffix(c.Path(), "fiberpow.sha256.min.js") {
c.Set(fiber.HeaderContentType, fiber.MIMETextJavaScriptCharsetUTF8)
c.Set(fiber.HeaderCacheControl, "public, max-age=57600, immutable")
return c.SendString(sha256Library)
}

// Checks if the user already solved the challenge.
secretCookie := c.Cookies("_challenge_n", "-1")
secretNumber, err := strconv.Atoi(secretCookie)
Expand Down
2 changes: 1 addition & 1 deletion views/challenge.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!DOCTYPE html><html lang="en"><head><title>Checking browser...</title></head><body><script type="text/javascript" src="./sha256.min.js"></script><script>async function main(){for(let a=0;; a++){if("%s"===await sha256(a+"-%s")){document.cookie="_challenge_n="+a,location.reload();break}}}main();</script><noscript>You need JavaScript to visit this website.</noscript></body></html>
<!DOCTYPE html><html lang="en"><head><title>Checking browser...</title></head><body><script type="text/javascript" src="./fiberpow.sha256.min.js"></script><script>async function main(){for(let a=0;; a++){if("%s"===await sha256(a+"-%s")){document.cookie="_challenge_n="+a,location.reload();break}}}main();</script><noscript>You need JavaScript to visit this website.</noscript></body></html>

0 comments on commit f1d3851

Please sign in to comment.