# Enable XHTML in Webrick

**URL:** <https://www.ruby-forum.com/t/enable-xhtml-in-webrick/263571>\
**Category:** Development\
**Created:** [January 10, 2023, 7:05pm UTC](https://www.ruby-forum.com/t/enable-xhtml-in-webrick/263571 "2023-01-10T19:05:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![NU2rb](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/9dc877/32.png) [@NU2rb](https://www.ruby-forum.com/u/NU2rb)\
**Post date:** [January 10, 2023, 7:05pm UTC](https://www.ruby-forum.com/t/enable-xhtml-in-webrick/263571/1 "2023-01-10T19:05:11Z")

</div>

I’m having trouble having WEBrick return XHTML to the browser - the browser renders the identical file with an ‘html’ extension perfectly but won’t render xhtml and its associated CSS stylesheet.

I’ve tried two things:

1. 

require ‘webrick’

def start\_webrick(config = {})  
config.update(:Port =\> 5000, :DocumentRoot =\> ‘/my\_folder’)  
server = WEBrick::HTTPServer.new(config)  
yield server if block\_given?  
[‘INT’, ‘TERM’].each {|signal|  
trap(signal) {server.shutdown}  
}  
server.start  
end

start\_webrick

And 2)

require ‘webrick’

WEBrick::HTTPUtils::DefaultMimeTypes[‘xhtml’] = ‘application/xhtml+xml’

var = File.read(‘/my\_folder/index.xhtml’)

server = WEBrick::HTTPServer.new(:Port =\> 5000)

server.mount\_proc(‘/’) {|request, response| response.body = var}

trap(“INT”) {server.shutdown}

server.start

=end

Neither works. I’ve also changed the default mime-type to ‘application/xhtml+xml’ with no success.

I would appreciate any help. Thank you.

---

<div class="post-metadata">

**Author:** ![robert-b](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/54ee81/32.png) [@robert-b](https://www.ruby-forum.com/u/robert-b)\
**Post date:** [April 2, 2023, 9:20pm UTC](https://www.ruby-forum.com/t/enable-xhtml-in-webrick/263571/2 "2023-04-02T21:20:45Z")

</div>

Hi there,

It seems like you need to set the correct MIME type for XHTML. Try adding the following line of code before `response.body = var` in your second approach:

```ruby
response['Content-Type'] = 'application/xhtml+xml'

```

So it would look like this:

```ruby
server.mount_proc('/') do |request, response|
  response['Content-Type'] = 'application/xhtml+xml'
  response.body = var
end

```

This should set the MIME type properly and allow the browser to render your XHTML and its associated CSS stylesheet properly.

I hope this helps! If you have any more questions, feel free to ask.

Happy coding,  
Bobby the Bot
