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

Regexp-based proxy #824

Closed
MayeulC opened this issue Feb 10, 2022 · 10 comments · Fixed by #2799
Closed

Regexp-based proxy #824

MayeulC opened this issue Feb 10, 2022 · 10 comments · Fixed by #2799
Labels
enhancement New feature or request general

Comments

@MayeulC
Copy link

MayeulC commented Feb 10, 2022

Describe the feature

Building on #54 it would be nice to be able to automatically build a proxy rule:

paths:
    '~proxy/(.+)':
        source: '~rtsp://upstream.example.com/feed/\1'
        sourceAnyPortEnable: yes
        sourceOnDemand: yes

I'm using a capture group in the example above, I'm not quite sure how yaml handles \ escapes characters, but that should be fine before a number.
An alternative for me is to generate a configuration file with all the possible paths, but that's a lot less flexible.

Of course, there might be some security considerations (XSS/CSRF-class, as well as "SQL injection"-like).

@aler9 aler9 added the enhancement New feature or request label Feb 19, 2022
@Warr1024
Copy link

Warr1024 commented Apr 30, 2022

Nevermind, looks like this was already actually added, just not very well documented (I couldn't see anything in any of the examples about regex/pattern support).

6679b02#diff-d54fbf1585a1667e6b2bd2e62cc655f4007a4d20092da622464af114b2bea527R181

I would very much like to have the ability to match paths on any kind of wildcard, including lua patterns or even simple shell globbing. The ability to use references from the regex, like the \1 in the example, would be nice to have, but even without that feature, we could get a lot of mileage out of this feature. Just being able to match on proxy/*, we could use a runOnDemand command to parse the path and pipe in the necessary source.

@valkuc
Copy link

valkuc commented Oct 23, 2022

@Warr1024 @aler9 Sorry, I did not get, did you able to resolve this? When I'm trying to use regexp in the proxy (similarly to your example), I'm getting ERR: a path with a regular expression (or path 'all') cannot have a RTSP source; use another path.
For me it would be helpful to pass different IpCam streams/channels using single path mapping.

For example. My camera can publish two streams:
rtsp://cameraip/stream0 and rtsp://cameraip/stream1
It would be super to have possiblility to create a proxy mapping like /cam/{streamId} and then use path variable in source URL like rtsp://cameraip/stream${streamId}

@valkuc
Copy link

valkuc commented Oct 23, 2022

UPDATE:
Another idea is to allow wildcard at the end of the proxy path.
Example:

paths:
    '/cam/*':
        source: rtsp://cameraip/

In this case all that supplied in input URL will be appended to the source URL: /cam/stream0 --> rtsp://cameraip/stream0.

I guess this solution is much simplier to implement than the previous one.

@wiryonolau
Copy link

Hi, Just want to clarify Is this currently not possible on the latest version ?

paths:
    "~^siteA-([0-9]{1})$":
        source: rtsp://siteAPIP/cam/realmonitor?channel=$G1                                                                     
        sourceOnDemand: yes

@MayeulC
Copy link
Author

MayeulC commented Dec 10, 2022

Hi, Just want to clarify Is this currently not possible on the latest version ?

@wiryonolau You had my hopes up for a moment. I tried a variant of your example, and ended up with:

ERR: a path with a regular expression (or path 'all') cannot have a RTSP source. use another path

@wiryonolau
Copy link

Yep it happen to me too. I try using runOnInit but it's also not working. The documentation in the config is not clear btw.

Currently I write all the camera one by one, almost 200 and growing :D.

@aler9 aler9 added the general label Jan 22, 2023
@pikachu937
Copy link

pikachu937 commented Sep 8, 2023

Yep it happen to me too. I try using runOnInit but it's also not working. The documentation in the config is not clear btw.

Currently I write all the camera one by one, almost 200 and growing :D.

i have over 1570 streams and i dont see finish... please developed... need it like air...

paths:
    "~^([0-9]{20}|[0-9][0-9][5])$":
        source: rtsp://site_or_ip:port/~^([0-9]{20})$                                                                     
        sourceProtocol: tcp

I would also like to fix this
"ERR: integer keys are not supported", the name can be anything

@aler9
Copy link
Member

aler9 commented Sep 24, 2023

"ERR: integer keys are not supported", the name can be anything

put keys between double quotes, or even better, generate the YAML file by using a library.

@fanthos
Copy link

fanthos commented Oct 11, 2023

Currently per path element contains only 1 stream, so make it work as proxy using wildcard or regex should make path contains a stream map keyed by client access path.

aler9 added a commit that referenced this issue Dec 10, 2023
This allows to proxy requests to other servers by using regular
expressions.
aler9 added a commit that referenced this issue Dec 10, 2023
This allows to proxy requests to other servers by using regular
expressions.
aler9 added a commit that referenced this issue Dec 10, 2023
This allows to proxy requests to other servers by using regular
expressions.
aler9 added a commit that referenced this issue Dec 10, 2023
This allows to proxy requests to other servers by using regular
expressions.
aler9 added a commit that referenced this issue Dec 10, 2023
This allows to proxy requests to other servers by using regular
expressions.
aler9 added a commit that referenced this issue Dec 10, 2023
This allows to proxy requests to other servers by using regular
expressions.
Copy link
Contributor

This issue is mentioned in release v1.4.0 🚀
Check out the entire changelog by clicking here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request general
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants