1
0
Fork 0
mirror of https://github.com/vbatts/imgsrv.git synced 2025-10-04 21:01:02 +00:00

vendoring sources, for posterity sake

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
This commit is contained in:
Vincent Batts 2019-03-11 15:31:42 -04:00
parent e06074e25a
commit 3c732c3b43
Signed by: vbatts
GPG key ID: 10937E57733F1362
416 changed files with 248911 additions and 2 deletions

27
vendor/github.com/vbatts/go-httplog/LICENSE generated vendored Normal file
View file

@ -0,0 +1,27 @@
Copyright (c) 2013 Vincent Batts <vbatts@hashbangbash.com>. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following disclaimer
in the documentation and/or other materials provided with the
distribution.
* Neither the name of Google Inc. nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

97
vendor/github.com/vbatts/go-httplog/httplog.go generated vendored Normal file
View file

@ -0,0 +1,97 @@
package httplog
import (
"fmt"
"net"
"net/http"
"strings"
"time"
"github.com/Sirupsen/logrus"
)
var (
/* This default icon is empty with a long lived cache */
DefaultFavIcon FavIcon = defaultFavIcon{}
)
type defaultFavIcon struct {
}
func (dfi defaultFavIcon) ServeHTTP(w http.ResponseWriter, r *http.Request) {
LogRequest(r, 200)
w.Header().Set("Cache-Control", "max-age=315360000")
}
/* simple interface for a favicon */
type FavIcon interface {
ServeHTTP(w http.ResponseWriter, r *http.Request)
}
// for debugging request headers
func LogHeaders(r *http.Request) {
fmt.Printf("HEADERS:\n")
for k, v := range r.Header {
fmt.Printf("\t%s\n", k)
for i, _ := range v {
fmt.Printf("\t\t%s\n", v[i])
}
}
}
/* kindof a common log type output */
func LogRequest(r *http.Request, statusCode int) {
var addr string
var user_agent string
user_agent = ""
addr = RealIP(r)
for k, v := range r.Header {
if k == "User-Agent" {
user_agent = strings.Join(v, " ")
}
if k == "X-Forwarded-For" {
addr = strings.Join(v, " ")
}
}
fmt.Printf("%s - - [%s] \"%s %s\" \"%s\" %d %d\n",
addr,
time.Now().Format(time.RFC1123Z),
r.Method,
r.URL.String(),
user_agent,
statusCode,
r.ContentLength)
}
func RealIP(r *http.Request) string {
rip := RealIPs(r)
if len(rip) == 0 {
return ""
}
return rip[len(rip)-1]
}
func RealIPs(r *http.Request) (ips []string) {
logrus.Infof("httplog: RemoteAddr: %q", r.RemoteAddr)
ip, _, err := net.SplitHostPort(r.RemoteAddr)
if err != nil {
logrus.Errorf("httplog: %q", err)
return nil
}
if ip != "" {
ips = append(ips, ip)
}
val := r.Header.Get("X-Forwarded-For")
logrus.Infof("httplog: X-Forwarded-For: %q", val)
if val != "" {
for _, ip := range strings.Split(val, ", ") {
ips = append(ips, ip)
}
}
return ips
}