Merge PR #1428
This commit is contained in:
commit
b2814e93a1
1 changed files with 8 additions and 1 deletions
|
|
@ -163,6 +163,9 @@ func (c *LINEChannel) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
c.webhookHandler(w, r)
|
c.webhookHandler(w, r)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MaxWebhookBodySize is the maximum allowed size for LINE webhook request body (1MB)
|
||||||
|
const MaxWebhookBodySize = 1 << 20 // 1MB
|
||||||
|
|
||||||
// webhookHandler handles incoming LINE webhook requests.
|
// webhookHandler handles incoming LINE webhook requests.
|
||||||
func (c *LINEChannel) webhookHandler(w http.ResponseWriter, r *http.Request) {
|
func (c *LINEChannel) webhookHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if r.Method != http.MethodPost {
|
if r.Method != http.MethodPost {
|
||||||
|
|
@ -175,7 +178,11 @@ func (c *LINEChannel) webhookHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
logger.ErrorCF("line", "Failed to read request body", map[string]any{
|
logger.ErrorCF("line", "Failed to read request body", map[string]any{
|
||||||
"error": err.Error(),
|
"error": err.Error(),
|
||||||
})
|
})
|
||||||
http.Error(w, "Bad request", http.StatusBadRequest)
|
if err.Error() == "http: request body too large" {
|
||||||
|
http.Error(w, "Request body too large", http.StatusRequestEntityTooLarge)
|
||||||
|
} else {
|
||||||
|
http.Error(w, "Bad request", http.StatusBadRequest)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if int64(len(body)) > maxWebhookBodySize {
|
if int64(len(body)) > maxWebhookBodySize {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue