summaryrefslogtreecommitdiffstats
path: root/internal/handler/submit.go
blob: 15251cf666c9de6e0253ee272ddc7c77cfb46a74 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package handler

import (
	"net/http"
	"nymdrop/internal/relay"
)

type Submit struct {
	relay *relay.Relay
}

func NewSubmit(r *relay.Relay) *Submit {
	return &Submit{relay: r}
}

func (s *Submit) ServeHTTP(w http.ResponseWriter, r *http.Request) {
	if r.Method != http.MethodPost {
		http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
		return
	}

	r.Body = http.MaxBytesReader(w, r.Body, 10*1024*1024)
	defer r.Body.Close()

	if err := s.relay.Forward(r.Body); err != nil {
		// Generic error — reveal nothing about internals.
		http.Error(w, "error", http.StatusInternalServerError)
		return
	}

	w.WriteHeader(http.StatusOK)
	w.Write([]byte("ok"))
}