# Reverse Mode: change request host, according to the SNI (HTTPS)

**URL:** <https://discourse.mitmproxy.org/t/reverse-mode-change-request-host-according-to-the-sni-https/466>\
**Category:** Uncategorized\
**Created:** [May 3, 2017, 4:53pm UTC](https://discourse.mitmproxy.org/t/reverse-mode-change-request-host-according-to-the-sni-https/466 "2017-05-03T16:53:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fakey](https://avatars.discourse-cdn.com/v4/letter/f/5f8ce5/32.png) [@fakey](https://discourse.mitmproxy.org/u/fakey)\
**Post date:** [May 3, 2017, 4:53pm UTC](https://discourse.mitmproxy.org/t/reverse-mode-change-request-host-according-to-the-sni-https/466/1 "2017-05-03T16:53:33Z")

</div>

Hi All,

I am trying to accept connections in Reverse mode, and set dynamic destination, according to the reverse URL being used.

The error message i am getting back from the proxy is: **_"Changing the Host server for HTTP/2 connections not allowed: [mitmproxy.org:443](http://mitmproxy.org:443)"_**

I did see people doing similar things, while in transparent/proxy mode, and HTTP.

Can it be done with Reverse and HTTPS?

Thanks!!

Sampe code for reference  
def request(flow: http.HTTPFlow) -\> None:

```
    if flow.client_conn.ssl_established:
        sni = flow.client_conn.connection.get_servername().decode(encoding='UTF-8')

    if 'first.domain.tld' in sni:
        flow.request.host = 'www.first.com'

    elif 'second.domain.tld' in sni:
        flow.request.host = 'www.second.com'

```

Some versions information:  
_Mitmproxy version: 2.0.2 (release version)_  
_Python version: 3.5.2_  
_Platform: Linux-4.4.0-66-generic-x86\_64-with-Ubuntu-16.04-xenial_  
_SSL version: OpenSSL 1.0.2g 1 Mar 2016_  
_Linux distro: Ubuntu 16.04 xenial_

---

<div class="post-metadata">

**Author:** ![fakey](https://avatars.discourse-cdn.com/v4/letter/f/5f8ce5/32.png) [@fakey](https://discourse.mitmproxy.org/u/fakey)\
**Post date:** [May 3, 2017, 5:18pm UTC](https://discourse.mitmproxy.org/t/reverse-mode-change-request-host-according-to-the-sni-https/466/2 "2017-05-03T17:18:35Z")

</div>

Ok, actually spent couple of hours digging around this yesterday, with no luck  
Just manged to get around it by adding " --no-http2" to mitmproxy on the command line

Will leave the post here for future reference, in case others will hit the same issue 🙂

Thanks!

---

<div class="post-metadata">

**Author:** ![mhils](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.mitmproxy.org/mhils/32/7_2.png) [@mhils](https://discourse.mitmproxy.org/u/mhils)\
**Post date:** [May 3, 2017, 10:24pm UTC](https://discourse.mitmproxy.org/t/reverse-mode-change-request-host-according-to-the-sni-https/466/3 "2017-05-03T22:24:22Z")

</div>

Thanks for the detailed write-up! Changing hosts with HTTP/2 is on our TODO list (#8 on [https://github.com/mitmproxy/mitmproxy/issues/1775](https://github.com/mitmproxy/mitmproxy/issues/1775)), but this is going to be pretty tricky to implement and please don’t expect it anytime soon 🙂 . As you already mentioned, the workaround is to add `--no-http2`.

Cheers,  
Max

---

<div class="post-metadata">

**Author:** ![zykzml7788](https://avatars.discourse-cdn.com/v4/letter/z/ce73a5/32.png) [@zykzml7788](https://discourse.mitmproxy.org/u/zykzml7788)\
**Post date:** [October 17, 2019, 2:32am UTC](https://discourse.mitmproxy.org/t/reverse-mode-change-request-host-according-to-the-sni-https/466/4 "2019-10-17T02:32:00Z")

</div>

Thanks!!! it can work!!!
