Skip to content
This repository has been archived by the owner on Mar 18, 2022. It is now read-only.

Commit

Permalink
Merge pull request #45 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 4.1.0
  • Loading branch information
andyone authored Dec 8, 2020
2 parents f316343 + 8063340 commit a4d92fc
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
5 changes: 4 additions & 1 deletion common/pkgre.spec
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

Summary: pkg.re morpher server
Name: pkgre
Version: 4.0.0
Version: 4.1.0
Release: 0%{?dist}
Group: Applications/System
License: Apache License, Version 2.0
Expand Down Expand Up @@ -153,6 +153,9 @@ rm -rf %{buildroot}
################################################################################

%changelog
* Tue Dec 08 2020 Anton Novojilov <[email protected]> - 4.1.0-0
- Fixed bug with proxying requests to GitHub

* Thu Nov 12 2020 Anton Novojilov <[email protected]> - 4.0.0-0
- Proxying all requests due to problems with Go Modules Services
- ek package updated to v12
Expand Down
22 changes: 17 additions & 5 deletions server/morpher/morpher.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package morpher
// ////////////////////////////////////////////////////////////////////////////////// //

import (
"bytes"
"errors"
"fmt"
"net/http"
Expand Down Expand Up @@ -62,6 +63,13 @@ type Metrics struct {

// ////////////////////////////////////////////////////////////////////////////////// //

var (
UAGit = []byte("git/") // Git User-Agent
UAGo = []byte("Go-http-client/") // Go User-Agent
)

// ////////////////////////////////////////////////////////////////////////////////// //

// majorVerRegExp regexp for extracting major version
var majorVerRegExp = regexp.MustCompile(`^[a-zA-Z]{0,}([0-9]{1}.*)`)

Expand Down Expand Up @@ -187,15 +195,19 @@ func requestHandler(ctx *fasthttp.RequestCtx) {
return
}

atomic.AddUint64(&metrics.Redirects, 1)

// Redirect to github
appendProcHeader(ctx, start)

url := repoInfo.GitHubURL(pkgInfo.TargetName)

log.Debug("Proxying request to %s", url)
proxyRequest(ctx, url)
// Proxy only requests from Go and Git
if bytes.HasPrefix(ctx.UserAgent(), UAGit) || bytes.HasPrefix(ctx.UserAgent(), UAGo) {
log.Debug("Proxying request to %s", url)
proxyRequest(ctx, url)
} else {
atomic.AddUint64(&metrics.Redirects, 1)
log.Debug("Redirecting request to %s", url)
redirectRequest(ctx, url)
}
}

// processBasicRequest redirect requests from main page to page defined in config
Expand Down
2 changes: 1 addition & 1 deletion server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
// Application info
const (
APP = "PkgRE Morpher Server"
VER = "4.0.0"
VER = "4.1.0"
DESC = "HTTP Server for morphing go get requests"
)

Expand Down

0 comments on commit a4d92fc

Please sign in to comment.