mirror of
https://github.com/masterking32/MasterHttpRelayVPN.git
synced 2026-05-18 23:54:37 +03:00
Add anti-buffering relay headers and optional randomized query suffixes
This commit is contained in:
@@ -107,6 +107,8 @@ func (s *Server) Run(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (s *Server) handleRelay(w http.ResponseWriter, r *http.Request) {
|
||||
applyRelayResponseHeaders(w.Header())
|
||||
|
||||
if r.Method != http.MethodPost {
|
||||
http.Error(w, "method not allowed", http.StatusMethodNotAllowed)
|
||||
return
|
||||
@@ -167,6 +169,13 @@ func (s *Server) handleRelay(w http.ResponseWriter, r *http.Request) {
|
||||
_, _ = w.Write(encrypted)
|
||||
}
|
||||
|
||||
func applyRelayResponseHeaders(header http.Header) {
|
||||
header.Set("Cache-Control", "no-store, no-cache, must-revalidate")
|
||||
header.Set("Pragma", "no-cache")
|
||||
header.Set("Expires", "0")
|
||||
header.Set("X-Accel-Buffering", "no")
|
||||
}
|
||||
|
||||
func (s *Server) processBatch(batch protocol.Batch) (protocol.Batch, error) {
|
||||
session := s.getOrCreateSession(batch.ClientSessionKey)
|
||||
now := time.Now()
|
||||
|
||||
@@ -3,6 +3,7 @@ package server
|
||||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"net/http/httptest"
|
||||
"sync"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -319,6 +320,27 @@ func TestSOCKSStateCloseUpstreamClearsConnectionSnapshot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleRelayAppliesAntiBufferingHeaders(t *testing.T) {
|
||||
srv := New(config.Config{}, nil)
|
||||
request := httptest.NewRequest("GET", "/relay", nil)
|
||||
recorder := httptest.NewRecorder()
|
||||
|
||||
srv.handleRelay(recorder, request)
|
||||
|
||||
if got := recorder.Header().Get("X-Accel-Buffering"); got != "no" {
|
||||
t.Fatalf("expected X-Accel-Buffering=no, got %q", got)
|
||||
}
|
||||
if got := recorder.Header().Get("Cache-Control"); got != "no-store, no-cache, must-revalidate" {
|
||||
t.Fatalf("unexpected Cache-Control header: %q", got)
|
||||
}
|
||||
if got := recorder.Header().Get("Pragma"); got != "no-cache" {
|
||||
t.Fatalf("unexpected Pragma header: %q", got)
|
||||
}
|
||||
if got := recorder.Header().Get("Expires"); got != "0" {
|
||||
t.Fatalf("unexpected Expires header: %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
func testDataPacket(clientSessionKey string, socksID uint64, sequence uint64, payload string) protocol.Packet {
|
||||
packet := protocol.NewPacket(clientSessionKey, protocol.PacketTypeSOCKSData)
|
||||
packet.SOCKSID = socksID
|
||||
|
||||
Reference in New Issue
Block a user