Proxy server implementation example needed
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 25/100
- Tipo de issue
- Documentación
- Claridad
- Necesita aclaración
- Estado de actividad
- Estancado
- Stack tecnológico
- swift
- Área
- api, backend, documentation
Línea de trabajo
Revisa el middleware de Vapor y los ejemplos de conversión de HTTPClient.Request/Response incluidos en el issue, y compáralos con la implementación de proxy de Hummingbird mencionada allí. Determina el alcance de un ejemplo documentado de proxy con async-http-client, incluido el manejo solicitado de JavaScript, la autorización y las cookies reenviadas; el trabajo estaría terminado con un ejemplo funcional y claramente delimitado.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Hello,
I need a proxy server endpoint for my Vapor project. The goal is to get the endpoint, which will take a URL as a parameter, get the page of that URL, modify it, and return it to the user. I've searched for an example here and over the internet but had no luck. Can I get the fully working thing I am trying to do with async-http-client? I need to proxy a page with JS, Google authorization, so I need to forward cookies etc.
The only useful thing I have found was the implementation of the proxy for the different Swift serverside framework - Hummingbird. It also uses async-http-client and the author says, that the implementation in Vapor will look similar.
Well, I am not a pro but here is what I have at the moment:
Proxy Middleware:
func respond(to request: Vapor.Request, chainingTo next: Vapor.AsyncResponder) async throws -> Vapor.Response {
// Convert to HTTPClient.Request
let ahcRequest = try await request.ahcRequest(host: target)
// Execute the request using httpClient
let clientResponse = httpClient.execute(request: ahcRequest)
// Convert HTTPClient.Response to Vapor.Response
var vaporResponse = try await clientResponse.get().vaporResponse
return vaporResponse
}
HTTP.Response -> Vapor.Response:
extension HTTPClient.Response {
var vaporResponse: Response {
var headers = HTTPHeaders()
self.headers.forEach { headers.add(name: $0.name, value: $0.value) }
let body: Response.Body
if let buffer = self.body {
body = .init(buffer: buffer)
} else {
body = .empty
}
return Response(
status: .init(statusCode: Int(self.status.code)),
headers: headers,
body: body
)
}
}
Vapor.Request -> async-http-client.Request:
extension Request {
func ahcRequest(host: String) async throws -> HTTPClient.Request {
let collectedBuffer = try await self.body.collect(max: 1024 * 1024).get()
return try HTTPClient.Request(
url: host,
method: self.method,
headers: self.headers,
body: collectedBuffer.map { HTTPClient.Body.byteBuffer($0) }
)
}
}
When I try to proxy the simple webpage with only HTML written - it works. But something more complicated fails.
If you have an example of how I can implement a working proxy for the modern websites, please share it with me.
Thanks.
- Lenguaje dominante
- Swift
- Estrellas
- 1.1k
- Forks
- 159
- Merge medio
- 1 h 22 min
- PR fusionados (30 d)
- 3
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de swift-server/async-http-client
-
RFC: pluggable authenticator APIAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 25/100
swift-server/async-http-client#946 · 2 comentarios ·
-
RequestBag keeps the request body after an early response with status >= 300Posiblemente ocupada @beshkenadze la tomó hace 16 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
-
HTTP/2 stream stays half-closed after an early response with status >= 300Posiblemente ocupada @beshkenadze la tomó hace 16 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
-
Transaction keeps the request body after an early response with status >= 300Posiblemente ocupada @beshkenadze la tomó hace 16 días. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 22/100
Todos los issues de swift-server/async-http-client
Issues similares
-
follow-up needs-triage S3: minor
Dificultad 1/5 1-3 horas Aptitud para principiantes 85/100
manaflow-ai/cmux#38032 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
arkavo-org/ArkavoKit#70 ·
Los mantenedores suelen responder en 1 día
-
[BUG] mo clean deletes Cypress test runner binaries in ~/Library/Caches/CypressPosiblemente ocupada @viniciusdsandrade la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
documentation good first issue help wanted P3 roadmap-v4
Dificultad 2/5 1-3 horas Aptitud para principiantes 90/100
maziyarpanahi/openmed#5429 ·
Los mantenedores suelen responder en 3 días