mirror of
https://github.com/wanghongenpin/proxypin.git
synced 2026-05-20 16:15:47 +08:00
Fix HTTP protocol request line URI and header host inconsistency (#361)
This commit is contained in:
@@ -19,6 +19,7 @@ import 'dart:math';
|
||||
import 'dart:typed_data';
|
||||
|
||||
import 'package:proxypin/network/channel.dart';
|
||||
import 'package:proxypin/network/host_port.dart';
|
||||
import 'package:proxypin/network/http/body_reader.dart';
|
||||
import 'package:proxypin/network/http/constants.dart';
|
||||
import 'package:proxypin/network/http/h2/codec.dart';
|
||||
@@ -225,11 +226,18 @@ class HttpRequestCodec extends HttpCodec<HttpRequest> {
|
||||
|
||||
@override
|
||||
void initialLine(BytesBuilder buffer, HttpRequest message) {
|
||||
String uri = message.uri;
|
||||
|
||||
//http scheme 输入地址和host不一致
|
||||
if (uri.startsWith(HostAndPort.httpScheme) && message.requestUri?.host != message.headers.host) {
|
||||
uri = message.requestUri?.replace(host: message.headers.host).toString() ?? uri;
|
||||
}
|
||||
|
||||
//请求行
|
||||
buffer
|
||||
..add(message.method.name.codeUnits)
|
||||
..addByte(HttpConstants.sp)
|
||||
..add(message.uri.codeUnits)
|
||||
..add(uri.codeUnits)
|
||||
..addByte(HttpConstants.sp)
|
||||
..add(message.protocolVersion.codeUnits)
|
||||
..addByte(HttpConstants.cr)
|
||||
|
||||
@@ -143,9 +143,15 @@ class HttpRequest extends HttpMessage {
|
||||
String get requestUrl => HostAndPort.startsWithScheme(uri) ? uri : '${remoteDomain()}$uri';
|
||||
|
||||
/// 请求的uri
|
||||
Uri? _requestUri;
|
||||
|
||||
Uri? get requestUri {
|
||||
if (_requestUri != null && _requestUri.toString() == requestUrl) {
|
||||
return _requestUri;
|
||||
}
|
||||
try {
|
||||
return Uri.parse(requestUrl);
|
||||
_requestUri ??= Uri.parse(requestUrl);
|
||||
return _requestUri;
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
@@ -155,22 +161,12 @@ class HttpRequest extends HttpMessage {
|
||||
String get domainPath => '${remoteDomain()}$path';
|
||||
|
||||
/// 请求的path
|
||||
String get path {
|
||||
try {
|
||||
var requestPath = Uri.parse(requestUrl).path;
|
||||
return requestPath.isEmpty ? "" : requestPath;
|
||||
} catch (e) {
|
||||
return "/";
|
||||
}
|
||||
}
|
||||
String get path => requestUri?.path ?? '';
|
||||
|
||||
Map<String, String> get queries {
|
||||
try {
|
||||
return Uri.parse(requestUrl).queryParameters;
|
||||
} catch (e) {
|
||||
return {};
|
||||
}
|
||||
}
|
||||
/// path and query
|
||||
String get pathAndQuery => '${requestUri?.path}${requestUri?.hasQuery == true ? '?${requestUri?.query}' : ''}';
|
||||
|
||||
Map<String, String> get queries => requestUri?.queryParameters ?? {};
|
||||
|
||||
///获取消息体编码
|
||||
@override
|
||||
@@ -215,7 +211,7 @@ class HttpRequest extends HttpMessage {
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'HttpRequest{version: $protocolVersion, url: $uri, method: ${method.name}, headers: $headers, contentLength: $contentLength, bodyLength: ${body?.length}}';
|
||||
return 'HttpRequest{version: $protocolVersion, uri: $uri, method: ${method.name}, headers: $headers, contentLength: $contentLength, bodyLength: ${body?.length}}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ class HttpClients {
|
||||
HostAndPort connectHost = proxyInfo == null ? hostAndPort : HostAndPort.host(proxyInfo.host, proxyInfo.port!);
|
||||
var channel = await client.connect(connectHost, channelContext);
|
||||
|
||||
if (proxyInfo != null && hostAndPort.isSsl()) {
|
||||
if (proxyInfo != null) {
|
||||
await connectRequest(hostAndPort, channel, proxyInfo: proxyInfo);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user