{"id":18456223,"url":"https://github.com/khezen/tarpit","last_synced_at":"2025-04-22T19:13:32.972Z","repository":{"id":57552630,"uuid":"138647833","full_name":"khezen/tarpit","owner":"khezen","description":"http tarpit middleware","archived":false,"fork":false,"pushed_at":"2019-01-01T09:50:45.000Z","size":29,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-22T19:13:29.199Z","etag":null,"topics":["delay","go","golang","http-middleware","tarpit"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/khezen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-25T20:41:59.000Z","updated_at":"2019-01-01T09:50:46.000Z","dependencies_parsed_at":"2022-09-26T18:50:41.124Z","dependency_job_id":null,"html_url":"https://github.com/khezen/tarpit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khezen%2Ftarpit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khezen%2Ftarpit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khezen%2Ftarpit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khezen%2Ftarpit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/khezen","download_url":"https://codeload.github.com/khezen/tarpit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250306642,"owners_count":21408926,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["delay","go","golang","http-middleware","tarpit"],"created_at":"2024-11-06T08:10:47.240Z","updated_at":"2025-04-22T19:13:32.952Z","avatar_url":"https://github.com/khezen.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# tarpit\n\n[![GoDoc](https://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)](https://godoc.org/github.com/khezen/tarpit)\n\n* simple HTTP middleware that purposely delays incoming request\n* repeted requests to a given resource increase the delay\n* enable TCP keep alive to keep the client from timing out\n\nOne typical use case is to protect authentication from brute force.\n\n## example\n\nThe following example applies tarpit based on IP address. It is possible to apply tarpit based on any data provided in the request.\n\n```golang\n\npackage main\n\nimport (\n    \"net/http\"\n    \"github.com/khezen/tarpit\"\n)\n\nvar tarpitMiddleware = tarpit.New(tarpit.DefaultFreeReqCount, tarpit.DefaultDelay, tarpit.DefaultResetPeriod)\n\nfunc handleGetMedicine(w http.ResponseWriter, r *http.Request) {\n    if r.Method != http.MethodGet{\n         w.WriteHeader(http.StatusMethodNotAllowed)\n         return\n    }\n    ipAddr := r.Header.Get(\"X-Forwarded-For\")\n    err := tarpitMiddleware.Tar(ipAddr, w, r)\n    if err != nil {\n        w.WriteHeader(http.StatusInternalServerError)\n        w.Write([]byte(err.Error()))\n        return\n    }\n    w.Write([]byte(\"Here is your medicine\"))\n}\n\nfunc main() {\n    http.HandleFunc(\"/drugs-store/v1/medicine\", handleGetMedicine)\n    writeTimeout := 30*time.Second\n    err := tarpit.ListenAndServe(\":80\", nil, writeTimeout)\n    if err != nil {\n        panic(err)\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhezen%2Ftarpit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhezen%2Ftarpit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhezen%2Ftarpit/lists"}