Skip to content

Commit

Permalink
fix #9
Browse files Browse the repository at this point in the history
  • Loading branch information
kataras committed Jul 22, 2020
1 parent bf801b9 commit 7d84b60
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 34 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go:
- 1.9.x
- 1.10.x
- 1.11.x
- 1.14.x
go_import_path: github.com/kataras/muxie
install:
- go get ./...
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2018-2019 Gerasimos Maropoulos <[email protected]>
Copyright (c) 2018-2020 Gerasimos Maropoulos <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<div align="center">
<!-- Release -->
<a href="https://github.com/kataras/muxie/releases">
<img src="https://img.shields.io/badge/release%20-v1.0.9-0077b3.svg?style=flat-squaree"
<img src="https://img.shields.io/badge/release%20-v1.10.0-0077b3.svg?style=flat-squaree"
alt="Release/stability" />
</a>
<!-- Godocs -->
Expand Down
2 changes: 1 addition & 1 deletion doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Source code and other details for the project are available at GitHub:
Current Version
1.0.9
1.10.0
Installation
Expand Down
9 changes: 1 addition & 8 deletions method_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,7 @@ var NoContentHandler http.Handler = http.HandlerFunc(func(w http.ResponseWriter,
type MethodHandler struct {
// origin *Mux

handlers map[string]http.Handler // method:handler
// Handle/HandleFunc can accept more than one methods per handler separated by comma or space,
// however in order to not repeat ourselves for every handler:
// extra methods will be not registered to a handler but they can register
// the route so it can be reachable, it is binded to a handler which just sends status no content,
// can be used for OPTIONS on cors.
noContentMethods []string

handlers map[string]http.Handler // method:handler
methodsAllowedStr string
}

Expand Down
62 changes: 39 additions & 23 deletions params_writer.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package muxie

import (
"net/http"
)
import "net/http"

// GetParam returns the path parameter value based on its key, i.e
// "/hello/:name", the parameter key is the "name".
Expand Down Expand Up @@ -54,13 +52,23 @@ type ParamEntry struct {
// that will be passed to the next handler in the chain.
type ResponseWriter interface {
http.ResponseWriter
http.Flusher
http.Pusher
http.Hijacker
http.CloseNotifier

ParamsSetter
Get(string) string
GetAll() []ParamEntry
}

type paramsWriter struct {
http.ResponseWriter
http.Flusher
http.Pusher
http.Hijacker
http.CloseNotifier

params []ParamEntry
}

Expand Down Expand Up @@ -103,27 +111,35 @@ func (pw *paramsWriter) GetAll() []ParamEntry {

func (pw *paramsWriter) reset(w http.ResponseWriter) {
pw.ResponseWriter = w
pw.params = pw.params[0:0]
}

// Flusher indicates if `Flush` is supported by the client.
//
// The default HTTP/1.x and HTTP/2 ResponseWriter implementations
// support Flusher, but ResponseWriter wrappers may not. Handlers
// should always test for this ability at runtime.
//
// Note that even for ResponseWriters that support Flush,
// if the client is connected through an HTTP proxy,
// the buffered data may not reach the client until the response
// completes.
func (pw *paramsWriter) Flusher() (http.Flusher, bool) {
flusher, canFlush := pw.ResponseWriter.(http.Flusher)
return flusher, canFlush
}
flusher, ok := w.(http.Flusher)
if !ok {
flusher = nil // make sure interface value is nil.
}

// Flush sends any buffered data to the client.
func (pw *paramsWriter) Flush() {
if flusher, ok := pw.Flusher(); ok {
flusher.Flush()
pusher, ok := w.(http.Pusher)
if !ok {
pusher = nil
}

hijacker, ok := w.(http.Hijacker)
if !ok {
hijacker = nil
}

// This interface is obselete by Go authors
// and we only capture it
// for compatible reasons. End-developers SHOULD replace
// the use of CloseNotifier with the: Request.Context().Done() channel.
closeNotifier, ok := w.(http.CloseNotifier)
if !ok {
closeNotifier = nil
}

pw.Flusher = flusher
pw.Pusher = pusher
pw.Hijacker = hijacker
pw.CloseNotifier = closeNotifier

pw.params = pw.params[0:0]
}

0 comments on commit 7d84b60

Please sign in to comment.