Skip to content

Commit

Permalink
support multiple HTTP methods except OPTIONs (#32)
Browse files Browse the repository at this point in the history
  • Loading branch information
adelowo authored Feb 13, 2024
1 parent ac7e90f commit b9b1093
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 7 deletions.
5 changes: 0 additions & 5 deletions config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,3 @@ http:

## enable /metrics endpoint and metrics collection?
is_enabled: true

prometheus:
username: sdump
password: sdump
is_enabled: true
1 change: 1 addition & 0 deletions ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ type RequestDefinition struct {
Headers http.Header `json:"headers,omitempty"`
IPAddress net.IP `json:"ip_address,omitempty" bson:"ip_address"`
Size int64 `json:"size,omitempty"`
Method string `json:"method,omitempty"`
}

type IngestHTTPRequest struct {
Expand Down
2 changes: 1 addition & 1 deletion internal/tui/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (i item) Title() string { return fmt.Sprintf("%s %s", i.ID, i.Request.IP
func (i item) Description() string {
return fmt.Sprintf("%s %s %s",
defaultTextStyle.Copy().Foreground(faintBuleColor).
Render("POST"), humanize.Bytes(uint64(i.Request.Size)), i.CreatedAt.Format("02/01/2006 15:04:05"))
Render(i.Request.Method), humanize.Bytes(uint64(i.Request.Size)), i.CreatedAt.Format("02/01/2006 15:04:05"))
}
func (i item) FilterValue() string { return i.ID }

Expand Down
2 changes: 1 addition & 1 deletion server/httpd/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func buildRoutes(cfg config.Config,
})

router.Post("/", urlHandler.create)
router.Post("/{reference}", urlHandler.ingest)
router.HandleFunc("/{reference}", urlHandler.ingest)
router.Get("/events", sseServer.ServeHTTP)

return tollbooth.LimitHandler(rateLimiter, router)
Expand Down
6 changes: 6 additions & 0 deletions server/httpd/url.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ func (u *urlHandler) ingest(w http.ResponseWriter, r *http.Request) {
ctx, span, requestID := getTracer(r.Context(), r, "url.ingest")
defer span.End()

if r.Method == http.MethodOptions {
_ = render.Render(w, r, newAPIError(http.StatusBadRequest, "Unsupported HTTP method"))
return
}

reference := chi.URLParam(r, "reference")

logger := u.logger.WithField("request_id", requestID).
Expand Down Expand Up @@ -223,6 +228,7 @@ func (u *urlHandler) ingest(w http.ResponseWriter, r *http.Request) {
Headers: r.Header,
IPAddress: util.GetIP(r),
Size: size,
Method: r.Method,
},
}

Expand Down

0 comments on commit b9b1093

Please sign in to comment.