Skip to content

Storing request specific context in Got #740

Description

@juhovh

Issuehunt badges

What would you like to discuss?

I would like to instrument a Got instance using beforeRequest, afterResponse and beforeError hooks. The plan is to create a new request context for each request in the beforeRequest hook and then access that context in the afterResponse and beforeError hooks to report the request's success/error status.

The natural way to do this would be to just mutate the options object in beforeRequest and set a new property containing the context, this is easy to access in both afterResponse and beforeError through the gotOptions given. My only worry is that by introducing new properties in the options there might be incompatibilities with other hooks or later versions of Got itself.

Are there any guidelines or rules of how to name custom variables inside options? Or alternatively is there any better place where I could store my custom property? I plan to release my instrumentation as a public library, so I just want to confirm that I'm not doing anything wrong here.

Checklist

  • I have read the documentation.

IssueHunt Summary

[
<
i
m
g

s
r
c

'
h
t
t
p
s
:
/
/
a
v
a
t
a
r
s
0
.
g
i
t
h
u
b
u
s
e
r
c
o
n
t
e
n
t
.
c
o
m
/
u
/
3
6
8
9
4
7
0
0
?
v

4
'

a
l
t

'
s
z
m
a
r
c
z
a
k
'

w
i
d
t
h

2
4

h
e
i
g
h
t

2
4

s
z
m
a
r
c
z
a
k
]
(
h
t
t
p
s
:
/
/
i
s
s
u
e
h
u
n
t
.
i
o
/
u
/
s
z
m
a
r
c
z
a
k
)

h
a
s

b
e
e
n

r
e
w
a
r
d
e
d
.

Backers (Total: $60.00)

Submitted pull Requests


Tips


IssueHunt has been backed by the following sponsors. Become a sponsor

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions