Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrectly parsing double header caused by Proxy #319 #451

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified VBA-Web - Blank.xlsm
Binary file not shown.
35 changes: 35 additions & 0 deletions src/WebResponse.cls
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,11 @@ End Sub
''
Public Sub CreateFromCurl(Client As WebClient, Request As WebRequest, Result As String)
On Error GoTo web_ErrorHandling

' Shengjun 2021/02/19 https://github.com/VBA-tools/VBA-Web/issues/319
If Client.ProxyServer <> "" Then
Result = CleanOutput(Result)
End If

Dim web_Lines() As String

Expand All @@ -191,6 +196,36 @@ web_ErrorHandling:
Err.Raise 11031 + vbObjectError, "WebResponse.CreateFromCurl", web_ErrorDescription
End Sub

' Shengjun 2021/02/19 https://github.com/VBA-tools/VBA-Web/issues/319

' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '
''
' CleanOutput
' Removes Proxy Server output before actual HTTP output from server, to fix parsing error
'
' @param {String} Output
' @param[out] {String} CleanOutput
''

Public Function CleanOutput(Original As String) As String

' Find the first empty line

Dim PosEmptyLine As Integer

CleanOutput = Original ' Set the output in case we don't start changing it

PosEmptyLine = InStr(1, Original, Chr(13) & Chr(10) & Chr(13) & Chr(10))
If (PosEmptyLine > 0) Then
' First empty line found
If (StrComp(Mid(Original, PosEmptyLine + 4, 4), "http", vbTextCompare) = 0) Then
' Line right after First empty line starts with HTTP. Remove everything before that
CleanOutput = Mid(Original, PosEmptyLine + 4)
End If

End If

End Function
''
' Extract headers from response headers
'
Expand Down