Proxy server implementation example needed
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
- Tipo di issue
- Documentazione
- Chiarezza
- Da chiarire
- Stato di attività
- Ferma
- Stack tecnologico
- swift
- Ambito
- api, backend, documentation
Direzione di ricerca
Esamina il middleware Vapor e gli esempi di conversione di HTTPClient.Request/Response presenti nell’issue, quindi confrontali con l’implementazione del proxy Hummingbird menzionata. Determina l’ambito di un esempio documentato di proxy async-http-client, inclusa la gestione richiesta di JavaScript, dell’autorizzazione e dei cookie inoltrati; il lavoro sarà completato quando sarà disponibile un esempio funzionante e chiaramente definito.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Swift
- Stelle
- 1.1k
- Fork
- 156
- Merge medio
- 1h 54m
- PR unite (30g)
- 4
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di swift-server/async-http-client
-
RequestBag keeps the request body after an early response with status >= 300Forse già presa @beshkenadze l’ha presa oggi. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
swift-server/async-http-client#941 ·
I maintainer di solito rispondono entro 1 giorno
-
HTTP/2 stream stays half-closed after an early response with status >= 300Forse già presa @beshkenadze l’ha presa oggi. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
swift-server/async-http-client#940 ·
I maintainer di solito rispondono entro 1 giorno
-
Transaction keeps the request body after an early response with status >= 300Forse già presa @beshkenadze l’ha presa oggi. Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
swift-server/async-http-client#939 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 22/100
swift-server/async-http-client#938 ·
I maintainer di solito rispondono entro 1 giorno
-
Invalid state: idleAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
swift-server/async-http-client#927 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di swift-server/async-http-client
Issue simili
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 76/100
logto-io/logto#9837 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
area: ios S3: minor
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
manaflow-ai/cmux#24404 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100