Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
U
ulfssar-go
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Faizal Aziz
ulfssar-go
Commits
8c00a559
Commit
8c00a559
authored
Mar 13, 2024
by
Faizal Aziz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding post form data with proxy
parent
4c6bbdac
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
0 deletions
+46
-0
client.go
pkg/http-client/client.go
+46
-0
No files found.
pkg/http-client/client.go
View file @
8c00a559
...
@@ -45,6 +45,7 @@ type (
...
@@ -45,6 +45,7 @@ type (
SetTimeout
(
timeout
time
.
Duration
)
SetTimeout
(
timeout
time
.
Duration
)
Post
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
payload
interface
{})
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
Post
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
payload
interface
{})
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
PostFormData
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
payload
map
[
string
]
string
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
PostFormData
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
payload
map
[
string
]
string
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
PostFormDataWithProxy
(
ctx
*
context
.
UlfsaarContext
,
path
,
ip
,
port
,
username
,
password
string
,
headers
http
.
Header
,
payload
map
[
string
]
string
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
PostMultipartFormFilesAndData
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
formData
[]
*
MultipartField
,
formFiles
[]
MultipartFileRequest
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
PostMultipartFormFilesAndData
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
formData
[]
*
MultipartField
,
formFiles
[]
MultipartFileRequest
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
PostWithProxy
(
ctx
*
context
.
UlfsaarContext
,
path
,
ip
,
port
,
username
,
password
string
,
headers
http
.
Header
,
payload
interface
{})
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
PostWithProxy
(
ctx
*
context
.
UlfsaarContext
,
path
,
ip
,
port
,
username
,
password
string
,
headers
http
.
Header
,
payload
interface
{})
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
Put
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
payload
interface
{})
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
Put
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
payload
interface
{})
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
...
@@ -271,6 +272,51 @@ func (c *client) PostFormData(ctx *context.UlfsaarContext, path string, headers
...
@@ -271,6 +272,51 @@ func (c *client) PostFormData(ctx *context.UlfsaarContext, path string, headers
return
respHeader
,
statusCode
,
body
,
httpErr
return
respHeader
,
statusCode
,
body
,
httpErr
}
}
func
(
c
*
client
)
PostFormDataWithProxy
(
ctx
*
context
.
UlfsaarContext
,
path
,
ip
,
port
,
username
,
password
string
,
headers
http
.
Header
,
payload
map
[
string
]
string
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
searchUrl
:=
c
.
options
.
Address
+
path
startTime
:=
time
.
Now
()
var
stringProxUrl
string
proxUrl
,
err
:=
url
.
Parse
(
fmt
.
Sprintf
(
"https://%s:%s@%s:%s"
,
username
,
password
,
ip
,
port
))
if
err
!=
nil
{
stringProxUrl
=
fmt
.
Sprintf
(
"https://%s:%s@%s:%s"
,
username
,
password
,
ip
,
port
)
}
else
{
stringProxUrl
=
proxUrl
.
String
()
}
request
:=
c
.
httpClient
.
SetProxy
(
stringProxUrl
)
.
R
()
for
h
,
val
:=
range
headers
{
request
.
Header
[
h
]
=
val
}
request
.
SetFormData
(
payload
)
if
headers
[
ContentType
]
==
nil
{
request
.
Header
.
Set
(
ContentType
,
ApplicationJSON
)
}
httpResp
,
httpErr
:=
request
.
Post
(
searchUrl
)
if
httpResp
!=
nil
{
body
=
httpResp
.
Body
()
respHeader
=
httpResp
.
Header
()
statusCode
=
httpResp
.
StatusCode
()
}
ctx
.
Info
(
"PostFormData"
,
logger
.
ToField
(
urlKey
,
searchUrl
),
logger
.
ToField
(
requestKey
,
toRequest
(
request
.
Header
,
payload
)),
logger
.
ToField
(
responseKey
,
toResponse
(
statusCode
,
respHeader
,
body
)),
logger
.
ToField
(
startProcessingTimeKey
,
startProcessingTime
(
startTime
)),
logger
.
ToField
(
processingTimeKey
,
processingTime
(
startTime
)),
)
if
statusCode
==
http
.
StatusOK
{
return
respHeader
,
statusCode
,
body
,
nil
}
return
respHeader
,
statusCode
,
body
,
httpErr
}
func
(
c
*
client
)
PostMultipartFormFilesAndData
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
formData
[]
*
MultipartField
,
formFiles
[]
MultipartFileRequest
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
func
(
c
*
client
)
PostMultipartFormFilesAndData
(
ctx
*
context
.
UlfsaarContext
,
path
string
,
headers
http
.
Header
,
formData
[]
*
MultipartField
,
formFiles
[]
MultipartFileRequest
)
(
respHeader
http
.
Header
,
statusCode
int
,
body
[]
byte
,
err
error
)
{
url
:=
c
.
options
.
Address
+
path
url
:=
c
.
options
.
Address
+
path
startTime
:=
time
.
Now
()
startTime
:=
time
.
Now
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment